Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACP-77: Implement Warp message verification #3423

Merged
merged 619 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 190 commits
Commits
Show all changes
619 commits
Select commit Hold shift + click to select a range
845f1d2
merged
StephenButtolph Oct 24, 2024
91a7cd7
fix test
StephenButtolph Oct 24, 2024
df02f3c
Merge branch 'update-state-staker-tests' into populate-subnet-public-…
StephenButtolph Oct 24, 2024
c848fee
fix test
StephenButtolph Oct 24, 2024
79c9b40
nit
StephenButtolph Oct 24, 2024
d8819fc
Merge branch 'master' into update-state-staker-tests
StephenButtolph Oct 24, 2024
667002e
Merge branch 'update-state-staker-tests' into populate-subnet-public-…
StephenButtolph Oct 24, 2024
31be1e2
merged
StephenButtolph Oct 24, 2024
fb7f564
Merge branch 'implement-acp-77-sov-validators-state' into implement-a…
StephenButtolph Oct 24, 2024
cd317f5
Merge branch 'implement-acp-77-deactivation' into implement-acp-77-up…
StephenButtolph Oct 24, 2024
9884275
Merge branch 'implement-acp-77-update-convert-subnet-tx' into impleme…
StephenButtolph Oct 24, 2024
ed2fcfd
simplify test
StephenButtolph Oct 24, 2024
c4f5652
Merge branch 'implement-acp-77-register-subnet-validator-tx' into imp…
StephenButtolph Oct 24, 2024
eb52075
Merge branch 'implement-acp-77--set-subnet-validator-weight-tx' into …
StephenButtolph Oct 24, 2024
8f0a080
merged
StephenButtolph Oct 24, 2024
d482de8
Merge branch 'populate-subnet-public-key-diffs' into implement-acp-77…
StephenButtolph Oct 24, 2024
fc27346
Merge branch 'implement-acp-77-sov-validators-state' into implement-a…
StephenButtolph Oct 24, 2024
e8b21ec
Verify no SoV + legacy overlap
StephenButtolph Oct 24, 2024
7f517c7
Fix legacy validator migration
StephenButtolph Oct 24, 2024
7d0d7e5
merged
StephenButtolph Oct 25, 2024
08bd9e3
ACP-77: Add subnetIDNodeID struct
StephenButtolph Oct 25, 2024
78c1c3d
nit
StephenButtolph Oct 26, 2024
6547c6d
Merge branch 'master' into implement-acp-77-add-subnetid-nodeid
StephenButtolph Oct 26, 2024
38ee164
Merge branch 'implement-acp-77-add-subnetid-nodeid' into implement-ac…
StephenButtolph Oct 26, 2024
d2137ef
fix merge
StephenButtolph Oct 26, 2024
5845d11
Split writeCurrentStakers into multiple functions
StephenButtolph Oct 26, 2024
6c3116a
merged
StephenButtolph Oct 27, 2024
d0d1602
reduce diff
StephenButtolph Oct 27, 2024
d397375
reduce diff
StephenButtolph Oct 27, 2024
5f8a09c
reduce diff
StephenButtolph Oct 27, 2024
3e9dc01
reduce diff
StephenButtolph Oct 27, 2024
da3a726
reduce diff
StephenButtolph Oct 27, 2024
8483ced
cleanup
StephenButtolph Oct 27, 2024
0507ce7
nit
StephenButtolph Oct 27, 2024
0022a65
Merge branch 'refactor-write-current-stakers' into implement-acp-77-s…
StephenButtolph Oct 27, 2024
8bbeee6
Add comment
StephenButtolph Oct 27, 2024
08dd776
comment
StephenButtolph Oct 27, 2024
255b0bf
nit
StephenButtolph Oct 27, 2024
3bc547d
reduce diff
StephenButtolph Oct 27, 2024
bff468d
Merge branch 'master' into refactor-write-current-stakers
StephenButtolph Oct 28, 2024
99f3c97
Merge branch 'refactor-write-current-stakers' into implement-acp-77-s…
StephenButtolph Oct 28, 2024
7cf1668
merged
StephenButtolph Oct 29, 2024
41f78f0
nit
StephenButtolph Oct 29, 2024
29cd6ba
nit
StephenButtolph Oct 29, 2024
8dfcbb1
Fix initValidatorSets
StephenButtolph Oct 29, 2024
ef29548
nit
StephenButtolph Oct 29, 2024
a77fb3c
test subnetIDNodeIDDB
StephenButtolph Oct 29, 2024
ce05dc8
fix comments
StephenButtolph Oct 29, 2024
3d04cef
nit
StephenButtolph Oct 29, 2024
dc35645
nit
StephenButtolph Oct 29, 2024
d472a9f
Reduce diff
StephenButtolph Oct 29, 2024
34ba29b
add comment
StephenButtolph Oct 29, 2024
97029aa
reduce diff
StephenButtolph Oct 30, 2024
dbeee70
Add NumSubnets to the validator manager interface
StephenButtolph Oct 30, 2024
729ded5
merged
StephenButtolph Oct 30, 2024
3621e53
add comment
StephenButtolph Oct 30, 2024
de2be9f
merged
StephenButtolph Oct 30, 2024
92a2277
Delete empty entries
StephenButtolph Oct 30, 2024
6375aa2
simplify state futher
StephenButtolph Oct 30, 2024
aedff15
nit
StephenButtolph Oct 30, 2024
1ac030a
nit
StephenButtolph Oct 30, 2024
9e0d7d5
Add caching
StephenButtolph Oct 31, 2024
9993b05
nit
StephenButtolph Oct 31, 2024
547d426
nit
StephenButtolph Oct 31, 2024
6bcc0ea
Add TODOs
StephenButtolph Oct 31, 2024
6065604
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 31, 2024
a7792c7
Add config changes to readme
StephenButtolph Oct 31, 2024
39b961b
Merge branch 'implement-acp-77-sov-validators-state' of github.com:av…
StephenButtolph Oct 31, 2024
4723c46
Improve doc for PutSubnetOnlyValidator
StephenButtolph Oct 31, 2024
46c4889
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Oct 31, 2024
a576cd1
merged
StephenButtolph Oct 31, 2024
f1ca6e6
Add test that decreases weight
StephenButtolph Oct 31, 2024
71f88e8
Fix regression
StephenButtolph Oct 31, 2024
c2ffd17
nit
StephenButtolph Oct 31, 2024
2b5d7c7
Merge branch 'implement-acp-77-sov-validators-state' into implement-a…
StephenButtolph Oct 31, 2024
91a6465
nit
StephenButtolph Oct 31, 2024
07370a5
nits
StephenButtolph Oct 31, 2024
23aff43
Add additional test
StephenButtolph Oct 31, 2024
66011f0
Move caching logic
StephenButtolph Nov 1, 2024
32bba0e
Merge branch 'master' into implement-acp-77-sov-validators-state
StephenButtolph Nov 1, 2024
d183148
merged
StephenButtolph Nov 1, 2024
b1bb458
nit
StephenButtolph Nov 1, 2024
ad31107
Add weight diff helpers
StephenButtolph Nov 1, 2024
cee236e
nit
StephenButtolph Nov 1, 2024
900eba3
add -> addOrSub
StephenButtolph Nov 1, 2024
fd48bde
merged
StephenButtolph Nov 2, 2024
7cbf31b
fix merge
StephenButtolph Nov 2, 2024
33d297d
Add test
StephenButtolph Nov 2, 2024
486f732
nit
StephenButtolph Nov 2, 2024
b448a04
reduce diff
StephenButtolph Nov 2, 2024
0685531
Add tests
StephenButtolph Nov 2, 2024
bb9f853
test excess and fees
StephenButtolph Nov 2, 2024
e6e3e76
Merge branch 'implement-acp-77-sov-validators-state' into implement-a…
StephenButtolph Nov 2, 2024
3077356
merged
StephenButtolph Nov 4, 2024
69837c1
improve caching
StephenButtolph Nov 4, 2024
8611fe4
Merge branch 'implement-acp-77-sov-validators-state' into implement-a…
StephenButtolph Nov 4, 2024
a5d3930
cleanup
StephenButtolph Nov 4, 2024
d74cdff
Simplify test
StephenButtolph Nov 4, 2024
7cddfc0
reduce diff
StephenButtolph Nov 4, 2024
afc9054
nit
StephenButtolph Nov 4, 2024
3c8246e
nit
StephenButtolph Nov 4, 2024
1268ed1
nit
StephenButtolph Nov 4, 2024
f7b75bc
nits
StephenButtolph Nov 4, 2024
82a249b
nit
StephenButtolph Nov 4, 2024
d37e9f3
nit
StephenButtolph Nov 5, 2024
9dc642a
num -> net for possibly negative value
StephenButtolph Nov 5, 2024
22de2b1
Address PR comments
StephenButtolph Nov 5, 2024
cc0e0ee
add comments
StephenButtolph Nov 5, 2024
33fea00
Merge branch 'implement-acp-77-sov-validators-state' into implement-a…
StephenButtolph Nov 5, 2024
915eb71
nit
StephenButtolph Nov 5, 2024
3811423
Merge branch 'implement-acp-77-deactivation' into implement-acp-77-up…
StephenButtolph Nov 5, 2024
b0c6f0b
merged
StephenButtolph Nov 5, 2024
74edd4f
reduce diff
StephenButtolph Nov 5, 2024
7d31e7a
nit
StephenButtolph Nov 5, 2024
fca9460
nit
StephenButtolph Nov 5, 2024
158621c
nit
StephenButtolph Nov 5, 2024
4c6462c
nit
StephenButtolph Nov 5, 2024
a217d1b
nit
StephenButtolph Nov 5, 2024
3987922
nit
StephenButtolph Nov 5, 2024
56475cf
Add nodeID tests
StephenButtolph Nov 5, 2024
db85cf1
ACP-77: Refactor e2e test
StephenButtolph Nov 5, 2024
8a18b14
nit
StephenButtolph Nov 5, 2024
6dc3e84
merged
StephenButtolph Nov 5, 2024
f8552ba
reduce diff
StephenButtolph Nov 5, 2024
7e1c545
merged
StephenButtolph Nov 5, 2024
88fe959
merged
StephenButtolph Nov 5, 2024
5b08c6a
test subnet state prior to conversion
StephenButtolph Nov 6, 2024
54b24e5
Merge branch 'implement-acp-77-update-convert-subnet-tx' into impleme…
StephenButtolph Nov 6, 2024
9884a93
nits
StephenButtolph Nov 6, 2024
a7cd427
nit
StephenButtolph Nov 6, 2024
4c2605c
wip
StephenButtolph Nov 6, 2024
20bd155
merged
StephenButtolph Nov 6, 2024
acf026a
comments
StephenButtolph Nov 6, 2024
bb0a605
merged
StephenButtolph Nov 6, 2024
0bf397a
Unexport AtomicTxExecutor
StephenButtolph Nov 6, 2024
5591626
nit
StephenButtolph Nov 6, 2024
0093c70
Unexport ProposalTxExecutor
StephenButtolph Nov 6, 2024
a0e6bcd
comment new function
StephenButtolph Nov 6, 2024
5e46925
nit
StephenButtolph Nov 6, 2024
706c833
Standardize standard tx executor
StephenButtolph Nov 7, 2024
3a01924
nit
StephenButtolph Nov 7, 2024
d7e00dd
nit
StephenButtolph Nov 7, 2024
56b0049
nit
StephenButtolph Nov 7, 2024
3540203
nit
StephenButtolph Nov 7, 2024
1bf8709
nit
StephenButtolph Nov 7, 2024
018b0aa
Comment
StephenButtolph Nov 7, 2024
bd6e10b
Remove P-chain txsmock package
StephenButtolph Nov 7, 2024
24c7d4b
nit
StephenButtolph Nov 7, 2024
833c04d
merged
StephenButtolph Nov 7, 2024
70a53b3
reduce diff
StephenButtolph Nov 7, 2024
26c3549
reduce diff
StephenButtolph Nov 7, 2024
877242f
reduce diff
StephenButtolph Nov 7, 2024
5110cfa
reduce diff
StephenButtolph Nov 7, 2024
e435ed7
reduce diff
StephenButtolph Nov 7, 2024
3750b1c
reduce diff
StephenButtolph Nov 7, 2024
687398e
reduce diff
StephenButtolph Nov 7, 2024
5a08505
reduce diff
StephenButtolph Nov 7, 2024
05d24ca
reduce diff
StephenButtolph Nov 7, 2024
37bede4
reduce diff
StephenButtolph Nov 7, 2024
3098c0b
reduce diff
StephenButtolph Nov 7, 2024
240f1e8
Standardize P-Chain tx visitor order
StephenButtolph Nov 7, 2024
e0ab968
merged
StephenButtolph Nov 7, 2024
efa35a4
nit
StephenButtolph Nov 7, 2024
031b989
nit
StephenButtolph Nov 7, 2024
a3f6186
Add tx builder test
StephenButtolph Nov 7, 2024
f767800
add comments
StephenButtolph Nov 7, 2024
0901618
Merge branch 'master' into standardize-p-chain-tx-vistors
StephenButtolph Nov 7, 2024
aedd8da
Merge branch 'standardize-p-chain-tx-vistors' into standardize-p-chai…
StephenButtolph Nov 7, 2024
e64ca23
Add RegisterSubnetValidatorTx serialization and SyntacticVerify tests
StephenButtolph Nov 7, 2024
4c86649
add TODO
StephenButtolph Nov 7, 2024
987c4e2
reduce diff
StephenButtolph Nov 7, 2024
e10a311
merged
StephenButtolph Nov 7, 2024
f55e2c0
Merge branch 'standardize-p-chain-visitor-order' into implement-acp-7…
StephenButtolph Nov 7, 2024
98ffb01
remove dead code
StephenButtolph Nov 7, 2024
6b23e82
Cleanup code
StephenButtolph Nov 7, 2024
c8f5157
nit
StephenButtolph Nov 7, 2024
a741fe9
merged
StephenButtolph Nov 7, 2024
af6171a
Add execution tests
StephenButtolph Nov 8, 2024
e3f6ab3
nit
StephenButtolph Nov 8, 2024
fc9440c
nit
StephenButtolph Nov 8, 2024
f41cff6
remove usage of defer
StephenButtolph Nov 8, 2024
e2b971e
merged
StephenButtolph Nov 8, 2024
38f63f9
nit
StephenButtolph Nov 8, 2024
aa4e859
nit
StephenButtolph Nov 8, 2024
a35c877
nit
StephenButtolph Nov 8, 2024
93ffbcd
Merge branch 'implement-acp-77-register-subnet-validator-tx' into imp…
StephenButtolph Nov 8, 2024
28b478b
oops
StephenButtolph Nov 8, 2024
db37d00
Merge branch 'implement-acp-77-register-subnet-validator-tx' into imp…
StephenButtolph Nov 8, 2024
3b1d5ca
nit
StephenButtolph Nov 8, 2024
9571693
nit
StephenButtolph Nov 8, 2024
30ac509
Address PR comments
StephenButtolph Nov 8, 2024
9769f21
Merge branch 'implement-acp-77-register-subnet-validator-tx' into imp…
StephenButtolph Nov 8, 2024
f16cc58
Address PR comments
StephenButtolph Nov 8, 2024
2947902
comment nits
StephenButtolph Nov 8, 2024
6357f5a
improve error reporting
StephenButtolph Nov 8, 2024
eaa7ea3
nit
StephenButtolph Nov 8, 2024
e2451ab
Add SetSubnetValidatorWeightTx serialization and SyntacticVerify tests
StephenButtolph Nov 8, 2024
6d04b1f
Add SetSubnetValidatorWeightTx builder tests
StephenButtolph Nov 8, 2024
b71faf7
execution test nits
StephenButtolph Nov 8, 2024
949da1d
Merge branch 'implement-acp-77-register-subnet-validator-tx' into imp…
StephenButtolph Nov 8, 2024
fde96e7
Add SetSubnetValidatorWeightTx execution tests
StephenButtolph Nov 8, 2024
c975b67
nit
StephenButtolph Nov 8, 2024
ddd97e3
Add overflow case
StephenButtolph Nov 8, 2024
d5148eb
merged
StephenButtolph Nov 8, 2024
6dc9f6d
merged
StephenButtolph Nov 8, 2024
5e49482
Merge branch 'implement-acp-77--set-subnet-validator-weight-tx' into …
StephenButtolph Nov 8, 2024
abae441
nits from PR review
StephenButtolph Nov 8, 2024
b3e1095
unexport visitor
StephenButtolph Nov 8, 2024
5f86e1a
add tx warp verifier tests
StephenButtolph Nov 9, 2024
4c9f376
Add block warp verifier
StephenButtolph Nov 9, 2024
b44a5eb
Reduce diff
StephenButtolph Nov 9, 2024
a4637e7
Refactor P-Chain configs
StephenButtolph Nov 10, 2024
e055312
Merge branch 'refactor-p-chain-configs' into implement-acp-77--set-su…
StephenButtolph Nov 11, 2024
5797442
merge
StephenButtolph Nov 11, 2024
6756ea0
Merge branch 'implement-acp-77--set-subnet-validator-weight-tx' into …
StephenButtolph Nov 11, 2024
22e6b6b
cleanup code
StephenButtolph Nov 11, 2024
d92a83d
fix unit tests
StephenButtolph Nov 11, 2024
024b042
nit renames
StephenButtolph Nov 11, 2024
33c2ac8
nit
StephenButtolph Nov 11, 2024
fa5f2cb
Merge branch 'refactor-p-chain-configs' into implement-acp-77--set-su…
StephenButtolph Nov 11, 2024
b413478
Merge branch 'implement-acp-77--set-subnet-validator-weight-tx' into …
StephenButtolph Nov 11, 2024
860fc32
Refactor subnet auth verification
StephenButtolph Nov 11, 2024
02fa55a
Merge branch 'refactor-subnet-auth-verification' into implement-acp-7…
StephenButtolph Nov 11, 2024
e42e213
Merge branch 'implement-acp-77--set-subnet-validator-weight-tx' into …
StephenButtolph Nov 11, 2024
4b36d76
merged
StephenButtolph Nov 12, 2024
ee3f305
Merge branch 'refactor-subnet-auth-verification' into implement-acp-7…
StephenButtolph Nov 12, 2024
b49f7f8
Merge branch 'implement-acp-77--set-subnet-validator-weight-tx' into …
StephenButtolph Nov 12, 2024
cdabac6
Add platform.getSubnetOnlyValidator API
StephenButtolph Nov 12, 2024
a513cf1
nit cleanup test
StephenButtolph Nov 12, 2024
0b529af
wip
StephenButtolph Nov 12, 2024
4935575
nits
StephenButtolph Nov 12, 2024
fd9e198
nit
StephenButtolph Nov 12, 2024
5953b6b
nit
StephenButtolph Nov 12, 2024
963b122
Add SoV deactivation owner support to the P-chain wallet
StephenButtolph Nov 12, 2024
44d3bd5
Merge branch 'add-validation-id-to-wallet' into implement-acp-77-warp…
StephenButtolph Nov 12, 2024
79cd3be
fix merge
StephenButtolph Nov 12, 2024
c7842c0
fix merge
StephenButtolph Nov 12, 2024
f7c3e71
nit
StephenButtolph Nov 13, 2024
a245061
Merge branch 'add-validation-id-to-wallet' into implement-acp-77-warp…
StephenButtolph Nov 13, 2024
039d539
Rename error to be more generic
StephenButtolph Nov 13, 2024
a14dc90
Merge branch 'rename-error' into add-get-subnet-only-validator-api
StephenButtolph Nov 13, 2024
06ce053
Merge branch 'add-get-subnet-only-validator-api' into add-validation-…
StephenButtolph Nov 13, 2024
c03ad3b
Merge branch 'add-validation-id-to-wallet' into implement-acp-77-warp…
StephenButtolph Nov 13, 2024
54f58a8
Merge branch 'master' into add-get-subnet-only-validator-api
StephenButtolph Nov 13, 2024
8806a57
Merge branch 'master' into add-get-subnet-only-validator-api
StephenButtolph Nov 13, 2024
d9b04ba
Address PR comments
StephenButtolph Nov 13, 2024
cfc0432
Merge branch 'add-get-subnet-only-validator-api' into add-validation-…
StephenButtolph Nov 13, 2024
137ce85
Merge branch 'master' into add-validation-id-to-wallet
StephenButtolph Nov 13, 2024
2fc07b3
Merge branch 'add-validation-id-to-wallet' into implement-acp-77-warp…
StephenButtolph Nov 13, 2024
52e04ff
Merge branch 'master' into implement-acp-77-warp-verification
StephenButtolph Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions database/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func GetUInt64(db KeyValueReader, key []byte) (uint64, error) {
return ParseUInt64(b)
}

func GetOrDefaultUInt64(db KeyValueReader, key []byte, def uint64) (uint64, error) {
v, err := GetUInt64(db, key)
if err == ErrNotFound {
return def, nil
}
return v, err
}

func PackUInt64(val uint64) []byte {
bytes := make([]byte, Uint64Size)
binary.BigEndian.PutUint64(bytes, val)
Expand Down
16 changes: 16 additions & 0 deletions ids/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ func (id ID) Prefix(prefixes ...uint64) ID {
return hashing.ComputeHash256Array(packer.Bytes)
}

// Append this id to create a more selective id.
//
// This is used to generate the ACP-77 validationIDs.
func (id ID) Append(suffixes ...uint32) ID {
packer := wrappers.Packer{
Bytes: make([]byte, IDLen+len(suffixes)*wrappers.IntLen),
}

packer.PackFixedBytes(id[:])
for _, suffix := range suffixes {
packer.PackInt(suffix)
}

return hashing.ComputeHash256Array(packer.Bytes)
}

// XOR this id and the provided id and return the resulting id.
//
// Note: this id is not modified.
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/snowman/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (e *Engine) Gossip(ctx context.Context) error {
// nodes with a large amount of stake weight.
vdrID, ok := e.ConnectedValidators.SampleValidator()
if !ok {
e.Ctx.Log.Warn("skipping block gossip",
e.Ctx.Log.Debug("skipping block gossip",
zap.String("reason", "no connected validators"),
)
return nil
Expand Down
2 changes: 1 addition & 1 deletion upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var (
DurangoTime: InitiallyActiveTime,
// Etna is left unactivated by default on local networks. It can be configured to
// activate by overriding the activation time in the upgrade file.
EtnaTime: UnscheduledActivationTime,
EtnaTime: InitiallyActiveTime,
}

ErrInvalidUpgradeTimes = errors.New("invalid upgrade configuration")
Expand Down
77 changes: 70 additions & 7 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/mempool"

smblock "github.com/ava-labs/avalanchego/snow/engine/snowman/block"
blockexecutor "github.com/ava-labs/avalanchego/vms/platformvm/block/executor"
txexecutor "github.com/ava-labs/avalanchego/vms/platformvm/txs/executor"
)
Expand All @@ -51,6 +52,7 @@ var (
)

type Builder interface {
smblock.BuildBlockWithContextChainVM
mempool.Mempool

// StartBlockTimer starts to issue block creation requests to advance the
Expand Down Expand Up @@ -182,7 +184,11 @@ func (b *builder) durationToSleep() (time.Duration, error) {

now := b.txExecutorBackend.Clk.Time()
maxTimeToAwake := now.Add(maxTimeToSleep)
nextStakerChangeTime, err := state.GetNextStakerChangeTime(preferredState, maxTimeToAwake)
nextStakerChangeTime, err := state.GetNextStakerChangeTime(
b.txExecutorBackend.Config.ValidatorFeeConfig,
preferredState,
maxTimeToAwake,
)
if err != nil {
return 0, fmt.Errorf("%w of %s: %w", errCalculatingNextStakerTime, preferredID, err)
}
Expand All @@ -204,10 +210,14 @@ func (b *builder) ShutdownBlockTimer() {
})
}

// BuildBlock builds a block to be added to consensus.
// This method removes the transactions from the returned
// blocks from the mempool.
func (b *builder) BuildBlock(context.Context) (snowman.Block, error) {
func (b *builder) BuildBlock(ctx context.Context) (snowman.Block, error) {
return b.BuildBlockWithContext(ctx, nil)
}

func (b *builder) BuildBlockWithContext(
ctx context.Context,
blockContext *smblock.Context,
) (snowman.Block, error) {
// If there are still transactions in the mempool, then we need to
// re-trigger block building.
defer b.Mempool.RequestBuildBlock(false /*=emptyBlockPermitted*/)
Expand All @@ -226,18 +236,29 @@ func (b *builder) BuildBlock(context.Context) (snowman.Block, error) {
return nil, fmt.Errorf("%w: %s", state.ErrMissingParentState, preferredID)
}

timestamp, timeWasCapped, err := state.NextBlockTime(preferredState, b.txExecutorBackend.Clk)
timestamp, timeWasCapped, err := state.NextBlockTime(
b.txExecutorBackend.Config.ValidatorFeeConfig,
preferredState,
b.txExecutorBackend.Clk,
)
if err != nil {
return nil, fmt.Errorf("could not calculate next staker change time: %w", err)
}

var pChainHeight uint64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming pChainHeight=0 is a valid input to buildBlock and subsequent function calls? Is this documented anywhere? I traced the call as far as BitSetSignature.Verify and wasn't seeing where this case was handled.

Copy link
Contributor Author

@StephenButtolph StephenButtolph Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing in pChainHeight=0 just means that the warp messages (if any existed) would be verified against the genesis state of the chain.

(Not that this particularly matters.. but) For Fuji and Mainnet, it is impossible to verify a warp message against block height = 0 because there are no validators with BLS keys in the genesis.

if blockContext != nil {
pChainHeight = blockContext.PChainHeight
}

statelessBlk, err := buildBlock(
ctx,
b,
preferredID,
nextHeight,
timestamp,
timeWasCapped,
preferredState,
pChainHeight,
)
if err != nil {
return nil, err
Expand All @@ -253,64 +274,83 @@ func (b *builder) PackAllBlockTxs() ([]*txs.Tx, error) {
return nil, fmt.Errorf("%w: %s", errMissingPreferredState, preferredID)
}

timestamp, _, err := state.NextBlockTime(preferredState, b.txExecutorBackend.Clk)
timestamp, _, err := state.NextBlockTime(
b.txExecutorBackend.Config.ValidatorFeeConfig,
preferredState,
b.txExecutorBackend.Clk,
)
if err != nil {
return nil, fmt.Errorf("could not calculate next staker change time: %w", err)
}

recommendedPChainHeight, err := b.txExecutorBackend.Ctx.ValidatorState.GetMinimumHeight(context.TODO())
ceyonur marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}

if !b.txExecutorBackend.Config.UpgradeConfig.IsEtnaActivated(timestamp) {
return packDurangoBlockTxs(
context.TODO(),
marun marked this conversation as resolved.
Show resolved Hide resolved
preferredID,
preferredState,
b.Mempool,
b.txExecutorBackend,
b.blkManager,
timestamp,
recommendedPChainHeight,
math.MaxInt,
)
}
return packEtnaBlockTxs(
context.TODO(),
preferredID,
preferredState,
b.Mempool,
b.txExecutorBackend,
b.blkManager,
timestamp,
recommendedPChainHeight,
math.MaxUint64,
)
}

// [timestamp] is min(max(now, parent timestamp), next staker change time)
func buildBlock(
ctx context.Context,
builder *builder,
parentID ids.ID,
height uint64,
timestamp time.Time,
forceAdvanceTime bool,
parentState state.Chain,
pChainHeight uint64,
) (block.Block, error) {
var (
blockTxs []*txs.Tx
err error
)
if builder.txExecutorBackend.Config.UpgradeConfig.IsEtnaActivated(timestamp) {
blockTxs, err = packEtnaBlockTxs(
ctx,
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
pChainHeight,
0, // minCapacity is 0 as we want to honor the capacity in state.
)
} else {
blockTxs, err = packDurangoBlockTxs(
ctx,
parentID,
parentState,
builder.Mempool,
builder.txExecutorBackend,
builder.blkManager,
timestamp,
pChainHeight,
targetBlockSize,
)
}
Expand Down Expand Up @@ -356,12 +396,14 @@ func buildBlock(
}

func packDurangoBlockTxs(
ctx context.Context,
parentID ids.ID,
parentState state.Chain,
mempool mempool.Mempool,
backend *txexecutor.Backend,
manager blockexecutor.Manager,
timestamp time.Time,
pChainHeight uint64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding, why are we adding the pChainHeight for packing Durango blocks when P-Chain Durango blocks aren't allowed to include ICM messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just so that we can call the same executeTx helper. The tx execution is enforcing which transactions are included when.

remainingSize int,
) ([]*txs.Tx, error) {
stateDiff, err := state.NewDiffOn(parentState)
Expand Down Expand Up @@ -389,11 +431,13 @@ func packDurangoBlockTxs(
}

shouldAdd, err := executeTx(
ctx,
parentID,
stateDiff,
mempool,
backend,
manager,
pChainHeight,
&inputs,
feeCalculator,
tx,
Expand All @@ -413,12 +457,14 @@ func packDurangoBlockTxs(
}

func packEtnaBlockTxs(
ctx context.Context,
parentID ids.ID,
parentState state.Chain,
mempool mempool.Mempool,
backend *txexecutor.Backend,
manager blockexecutor.Manager,
timestamp time.Time,
pChainHeight uint64,
minCapacity gas.Gas,
) ([]*txs.Tx, error) {
stateDiff, err := state.NewDiffOn(parentState)
Expand Down Expand Up @@ -462,11 +508,13 @@ func packEtnaBlockTxs(
}

shouldAdd, err := executeTx(
ctx,
parentID,
stateDiff,
mempool,
backend,
manager,
pChainHeight,
&inputs,
feeCalculator,
tx,
Expand All @@ -486,11 +534,13 @@ func packEtnaBlockTxs(
}

func executeTx(
ctx context.Context,
parentID ids.ID,
stateDiff state.Diff,
mempool mempool.Mempool,
backend *txexecutor.Backend,
manager blockexecutor.Manager,
pChainHeight uint64,
inputs *set.Set[ids.ID],
feeCalculator fee.Calculator,
tx *txs.Tx,
Expand All @@ -499,6 +549,19 @@ func executeTx(

// Invariant: [tx] has already been syntactically verified.

err := txexecutor.VerifyWarpMessages(
ctx,
backend.Ctx.NetworkID,
backend.Ctx.ValidatorState,
pChainHeight,
tx.Unsigned,
)
if err != nil {
txID := tx.ID()
mempool.MarkDropped(txID, err)
return false, nil
}

txDiff, err := state.NewDiffOn(stateDiff)
if err != nil {
return false, err
Expand Down
42 changes: 33 additions & 9 deletions vms/platformvm/block/executor/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,49 @@ func (*Block) ShouldVerifyWithContext(context.Context) (bool, error) {
return true, nil
}

func (b *Block) VerifyWithContext(_ context.Context, ctx *smblock.Context) error {
pChainHeight := uint64(0)
if ctx != nil {
pChainHeight = ctx.PChainHeight
func (b *Block) VerifyWithContext(ctx context.Context, blockContext *smblock.Context) error {
var pChainHeight uint64
if blockContext != nil {
pChainHeight = blockContext.PChainHeight
}

blkID := b.ID()
if blkState, ok := b.manager.blkIDToState[blkID]; ok {
if !blkState.verifiedHeights.Contains(pChainHeight) {
// PlatformVM blocks are currently valid regardless of the ProposerVM's
// PChainHeight. If this changes, those validity checks should be done prior
// to adding [pChainHeight] to [verifiedHeights].
// Only the validity of warp messages need to be verified because
// this block has already passed verification with a different
// height.
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved
err := VerifyWarpMessages(
ctx,
b.manager.ctx.NetworkID,
b.manager.ctx.ValidatorState,
pChainHeight,
b,
)
if err != nil {
return err
}

blkState.verifiedHeights.Add(pChainHeight)
}

// This block has already been verified.
return nil
return nil // This block has already been executed.
}

// Verify the warp messages in the block.
err := VerifyWarpMessages(
ctx,
b.manager.ctx.NetworkID,
b.manager.ctx.ValidatorState,
pChainHeight,
b,
)
if err != nil {
return err
}
StephenButtolph marked this conversation as resolved.
Show resolved Hide resolved

// Since the warp messages are valid, we need to execute the rest of the
// validity checks.
return b.Visit(&verifier{
backend: b.manager.backend,
txExecutorBackend: b.manager.txExecutorBackend,
Expand Down
Loading
Loading