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 250 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
3 changes: 3 additions & 0 deletions snow/snowtest/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func Context(tb testing.TB, chainID ids.ID) *snow.Context {
require.NoError(aliaser.Alias(CChainID, CChainID.String()))

validatorState := &validatorstest.State{
GetMinimumHeightF: func(context.Context) (uint64, error) {
return 0, nil
},
GetSubnetIDF: func(_ context.Context, chainID ids.ID) (ids.ID, error) {
subnetID, ok := map[ids.ID]ids.ID{
constants.PlatformChainID: constants.PrimaryNetworkID,
Expand Down
59 changes: 55 additions & 4 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 @@ -208,10 +210,19 @@ 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,
&smblock.Context{
PChainHeight: 0,
},
)
}

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 Down Expand Up @@ -240,12 +251,14 @@ func (b *builder) BuildBlock(context.Context) (snowman.Block, error) {
}

statelessBlk, err := buildBlock(
ctx,
b,
preferredID,
nextHeight,
timestamp,
timeWasCapped,
preferredState,
blockContext.PChainHeight,
)
if err != nil {
return nil, err
Expand All @@ -270,59 +283,74 @@ func (b *builder) PackAllBlockTxs() ([]*txs.Tx, error) {
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 @@ -368,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 @@ -401,11 +431,13 @@ func packDurangoBlockTxs(
}

shouldAdd, err := executeTx(
ctx,
parentID,
stateDiff,
mempool,
backend,
manager,
pChainHeight,
&inputs,
feeCalculator,
tx,
Expand All @@ -425,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 @@ -474,11 +508,13 @@ func packEtnaBlockTxs(
}

shouldAdd, err := executeTx(
ctx,
parentID,
stateDiff,
mempool,
backend,
manager,
pChainHeight,
&inputs,
feeCalculator,
tx,
Expand All @@ -498,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 @@ -511,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
1 change: 1 addition & 0 deletions vms/platformvm/block/builder/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func newWallet(t testing.TB, e *environment, c walletConfig) wallet.Wallet {
e.state,
secp256k1fx.NewKeychain(c.keys...),
c.subnetIDs,
nil, // validationIDs
[]ids.ID{e.ctx.CChainID, e.ctx.XChainID},
)
}
Expand Down
45 changes: 30 additions & 15 deletions vms/platformvm/block/executor/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +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 {
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].
blkState.verifiedHeights.Add(pChainHeight)
blkState, previouslyExecuted := b.manager.blkIDToState[blkID]
warpAlreadyVerified := previouslyExecuted && blkState.verifiedHeights.Contains(blockContext.PChainHeight)

// If the chain is bootstrapped and the warp messages haven't been verified,
// we must verify them.
if !warpAlreadyVerified && b.manager.txExecutorBackend.Bootstrapped.Get() {
err := VerifyWarpMessages(
ctx,
b.manager.ctx.NetworkID,
b.manager.ctx.ValidatorState,
blockContext.PChainHeight,
b,
)
if err != nil {
return err
}
}

// This block has already been verified.
// If the block was previously executed, we don't need to execute it again,
// we can just mark that the warp messages are valid at this height.
if previouslyExecuted {
blkState.verifiedHeights.Add(blockContext.PChainHeight)
ceyonur marked this conversation as resolved.
Show resolved Hide resolved
return nil
}

// Since this is the first time we are verifying this block, we must execute
// the state transitions to generate the state diffs.
return b.Visit(&verifier{
backend: b.manager.backend,
txExecutorBackend: b.manager.txExecutorBackend,
pChainHeight: pChainHeight,
pChainHeight: blockContext.PChainHeight,
})
}

func (b *Block) Verify(ctx context.Context) error {
return b.VerifyWithContext(ctx, nil)
return b.VerifyWithContext(
ctx,
&smblock.Context{
PChainHeight: 0,
},
)
}

func (b *Block) Accept(context.Context) error {
Expand Down
1 change: 1 addition & 0 deletions vms/platformvm/block/executor/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func newWallet(t testing.TB, e *environment, c walletConfig) wallet.Wallet {
e.state,
secp256k1fx.NewKeychain(c.keys...),
c.subnetIDs,
nil, // validationIDs
[]ids.ID{e.ctx.CChainID, e.ctx.XChainID},
)
}
Expand Down
16 changes: 16 additions & 0 deletions vms/platformvm/block/executor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package executor

import (
"context"
"errors"

"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -122,6 +123,21 @@ func (m *manager) VerifyTx(tx *txs.Tx) error {
return ErrChainNotSynced
}

recommendedPChainHeight, err := m.ctx.ValidatorState.GetMinimumHeight(context.TODO())
if err != nil {
return err
}
err = executor.VerifyWarpMessages(
context.TODO(),
m.ctx.NetworkID,
m.ctx.ValidatorState,
recommendedPChainHeight,
darioush marked this conversation as resolved.
Show resolved Hide resolved
tx.Unsigned,
)
if err != nil {
return err
}

stateDiff, err := state.NewDiff(m.preferred, m)
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions vms/platformvm/block/executor/verifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func TestVerifierVisitAtomicBlock(t *testing.T) {
verifier.state,
secp256k1fx.NewKeychain(genesis.EWOQKey),
nil, // subnetIDs
nil, // validationIDs
nil, // chainIDs
)
exportedOutput = &avax.TransferableOutput{
Expand Down Expand Up @@ -346,6 +347,7 @@ func TestVerifierVisitStandardBlock(t *testing.T) {
verifier.state,
secp256k1fx.NewKeychain(genesis.EWOQKey),
nil, // subnetIDs
nil, // validationIDs
[]ids.ID{ctx.XChainID}, // Read the UTXO to import
)
initialTimestamp = verifier.state.GetTimestamp()
Expand Down Expand Up @@ -463,7 +465,8 @@ func TestVerifierVisitCommitBlock(t *testing.T) {
Config: &config.Internal{
UpgradeConfig: upgradetest.GetConfig(upgradetest.ApricotPhasePost6),
},
Clk: &mockable.Clock{},
Clk: &mockable.Clock{},
Bootstrapped: utils.NewAtomic(true),
},
backend: backend,
}
Expand Down Expand Up @@ -530,7 +533,8 @@ func TestVerifierVisitAbortBlock(t *testing.T) {
Config: &config.Internal{
UpgradeConfig: upgradetest.GetConfig(upgradetest.ApricotPhasePost6),
},
Clk: &mockable.Clock{},
Clk: &mockable.Clock{},
Bootstrapped: utils.NewAtomic(true),
},
backend: backend,
}
Expand Down Expand Up @@ -1098,6 +1102,7 @@ func TestBlockExecutionWithComplexity(t *testing.T) {
verifier.state,
secp256k1fx.NewKeychain(genesis.EWOQKey),
nil, // subnetIDs
nil, // validationIDs
nil, // chainIDs
)

Expand Down
Loading
Loading