-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathconstants.go
119 lines (93 loc) · 5.56 KB
/
constants.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package flow
import (
"fmt"
"time"
)
// GenesisTime defines the timestamp of the genesis block.
var GenesisTime = time.Date(2018, time.December, 19, 22, 32, 30, 42, time.UTC)
// DefaultProtocolVersion is the default protocol version, indicating none was
// explicitly set during bootstrapping.
const DefaultProtocolVersion uint = 0
// DefaultTransactionExpiry is the default expiry for transactions, measured in blocks.
// The default value is equivalent to 10 minutes for a 1-second block time.
//
// Let E by the transaction expiry. If a transaction T specifies a reference
// block R with height H, then T may be included in any block B where:
// * R<-*B - meaning B has R as an ancestor, and
// * R.height < B.height <= R.height+E
const DefaultTransactionExpiry = 10 * 60
// DefaultTransactionExpiryBuffer is the default buffer time between a transaction being ingested by a
// collection node and being included in a collection and block.
const DefaultTransactionExpiryBuffer = 30
// DefaultMaxTransactionGasLimit is the default maximum value for the transaction gas limit.
const DefaultMaxTransactionGasLimit = 9999
// DefaultMaxTransactionByteSize is the default maximum transaction byte size. (~1.5MB)
const DefaultMaxTransactionByteSize = 1_500_000
// DefaultMaxCollectionByteSize is the default maximum value for a collection byte size.
const DefaultMaxCollectionByteSize = 3_000_000 // ~3MB. This is should always be higher than the limit on single tx size.
// DefaultMaxCollectionTotalGas is the default maximum value for total gas allowed to be included in a collection.
const DefaultMaxCollectionTotalGas = 10_000_000 // 10M
// DefaultMaxCollectionSize is the default maximum number of transactions allowed inside a collection.
const DefaultMaxCollectionSize = 100
// DefaultValueLogGCWaitDuration is the default wait duration before we repeatedly call the badger value log GC.
const DefaultValueLogGCWaitDuration time.Duration = 10 * time.Minute
// DefaultRequiredApprovalsForSealConstruction is the default number of approvals required to construct a candidate seal
// for subsequent inclusion in block.
// when set to 1, it requires at least 1 approval to build a seal
// when set to 0, it can build seal without any approval
const DefaultRequiredApprovalsForSealConstruction = uint(1)
// DefaultRequiredApprovalsForSealValidation is the default number of approvals that should be
// present and valid for each chunk. Setting this to 0 will disable counting of chunk approvals
// this can be used temporarily to ease the migration to new chunk based sealing.
// TODO:
// - This value will result in consensus not depending on verification at all for sealing (no approvals required)
// - Full protocol should be +2/3 of all currently authorized verifiers.
const DefaultRequiredApprovalsForSealValidation = 0
// DefaultChunkAssignmentAlpha is the default number of verifiers that should be
// assigned to each chunk.
const DefaultChunkAssignmentAlpha = 3
// DefaultEmergencySealingActive is a flag which indicates when emergency sealing is active, this is a temporary measure
// to make fire fighting easier while seal & verification is under development.
const DefaultEmergencySealingActive = false
// threshold for re-requesting approvals: min height difference between the latest finalized block
// and the block incorporating a result
const DefaultApprovalRequestsThreshold = uint64(10)
// DomainTagLength is set to 32 bytes.
//
// Signatures on Flow that needs to be scoped to a certain domain need to
// have the same length in order to avoid tag collision issues, when prefixing the
// message to sign.
const DomainTagLength = 32
const TransactionTagString = "FLOW-V0.0-transaction"
// TransactionDomainTag is the prefix of all signed transaction payloads.
//
// The tag is the string `TransactionTagString` encoded as UTF-8 bytes,
// right padded to a total length of 32 bytes.
var TransactionDomainTag = paddedDomainTag(TransactionTagString)
// paddedDomainTag padds string tags to form the actuatl domain separation tag used for signing
// and verifiying.
//
// A domain tag is encoded as UTF-8 bytes, right padded to a total length of 32 bytes.
func paddedDomainTag(s string) [DomainTagLength]byte {
var tag [DomainTagLength]byte
if len(s) > DomainTagLength {
panic(fmt.Sprintf("domain tag %s cannot be longer than %d characters", s, DomainTagLength))
}
copy(tag[:], s)
return tag
}
// EstimatedComputationPerMillisecond is the approximate number of computation units that can be performed in a millisecond.
// this was calibrated during the Variable Transaction Fees: Execution Effort FLIP https://github.com/onflow/flow/pull/753.
// Updated after the FLIP:
// https://github.com/onflow/flips/blob/14c5ec4/governance/20240508-computation-limit-hike.md#flip-267-increasing-the-transaction-computation-limit
const EstimatedComputationPerMillisecond = 9999.0 / 1000.0
// NormalizedExecutionTimePerComputationUnit returns the normalized time per computation unit
// If the computation estimation is correct (as per the FLIP https://github.com/onflow/flow/pull/753) the value should be 1.
// If the value is greater than 1, the computation estimation is too low; we are underestimating transaction complexity (and thus undercharging).
// If the value is less than 1, the computation estimation is too high; we are overestimating transaction complexity (and thus overcharging).
func NormalizedExecutionTimePerComputationUnit(execTime time.Duration, computationUsed uint64) float64 {
if computationUsed == 0 {
return 0
}
return (float64(execTime.Milliseconds()) / float64(computationUsed)) * EstimatedComputationPerMillisecond
}