Skip to content

Commit 1097d82

Browse files
committed
This commit removes the toEngine channel pattern from all VMs and adds an additional API:
``` SubscribeToEvents(ctx context.Context) Message) ``` Which returns when an event (pending transactions or state sync done Message) is sent by the VM. Unlike the toEngine pattern which only notifies the consumer a single time until a block is built, successive calls to `SubscribeToEvents` will return that transactions are pending as long as the mem-pool is not empty and a block can be built, otherwise the calls block. The API change is needed to support consensus protocols which facilitate censorship resistance as part of their protocol and therefore need information about whether a block should be built or not on demand, in contrast to the curren toEngine pattern which notifies the consensus when new transactions arrive only once, and then block building may even fail. Having such an API on the VM side (and not implementing the logic in consensus) forces the VM to handle any side effects of block building (such as re-introducing transactions into the mempool). Signed-off-by: Yacov Manevich <yacov.manevich@avalabs.org>
1 parent 7d555ea commit 1097d82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1701
-507
lines changed

chains/linearizable_vm.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ type initializeOnLinearizeVM struct {
3333
genesisBytes []byte
3434
upgradeBytes []byte
3535
configBytes []byte
36-
toEngine chan<- common.Message
3736
fxs []*common.Fx
3837
appSender common.AppSender
3938
}
4039

40+
func (vm *initializeOnLinearizeVM) SubscribeToEvents(ctx context.Context) common.Message {
41+
return vm.vmToInitialize.SubscribeToEvents(ctx)
42+
}
43+
4144
func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID ids.ID) error {
4245
vm.vmToLinearize.stopVertexID = stopVertexID
4346
return vm.vmToInitialize.Initialize(
@@ -47,7 +50,6 @@ func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID i
4750
vm.genesisBytes,
4851
vm.upgradeBytes,
4952
vm.configBytes,
50-
vm.toEngine,
5153
vm.fxs,
5254
vm.appSender,
5355
)
@@ -74,9 +76,8 @@ func (vm *linearizeOnInitializeVM) Initialize(
7476
_ []byte,
7577
_ []byte,
7678
_ []byte,
77-
toEngine chan<- common.Message,
7879
_ []*common.Fx,
7980
_ common.AppSender,
8081
) error {
81-
return vm.Linearize(ctx, vm.stopVertexID, toEngine)
82+
return vm.Linearize(ctx, vm.stopVertexID)
8283
}

chains/manager.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -727,10 +727,6 @@ func (m *manager) createAvalancheChain(
727727
},
728728
)
729729

730-
// The channel through which a VM may send messages to the consensus engine
731-
// VM uses this channel to notify engine that a block is ready to be made
732-
msgChan := make(chan common.Message, defaultChannelSize)
733-
734730
// The only difference between using avalancheMessageSender and
735731
// snowmanMessageSender here is where the metrics will be placed. Because we
736732
// end up using this sender after the linearization, we pass in
@@ -742,7 +738,6 @@ func (m *manager) createAvalancheChain(
742738
genesisData,
743739
chainConfig.Upgrade,
744740
chainConfig.Config,
745-
msgChan,
746741
fxs,
747742
snowmanMessageSender,
748743
)
@@ -823,7 +818,6 @@ func (m *manager) createAvalancheChain(
823818
genesisBytes: genesisData,
824819
upgradeBytes: chainConfig.Upgrade,
825820
configBytes: chainConfig.Config,
826-
toEngine: msgChan,
827821
fxs: fxs,
828822
appSender: snowmanMessageSender,
829823
}
@@ -885,8 +879,8 @@ func (m *manager) createAvalancheChain(
885879
// Asynchronously passes messages from the network to the consensus engine
886880
h, err := handler.New(
887881
ctx,
882+
linearizableVM,
888883
vdrs,
889-
msgChan,
890884
m.FrontierPollFrequency,
891885
m.ConsensusAppConcurrency,
892886
m.ResourceTracker,
@@ -1202,18 +1196,13 @@ func (m *manager) createSnowmanChain(
12021196
vm = tracedvm.NewBlockVM(vm, "proposervm", m.Tracer)
12031197
}
12041198

1205-
// The channel through which a VM may send messages to the consensus engine
1206-
// VM uses this channel to notify engine that a block is ready to be made
1207-
msgChan := make(chan common.Message, defaultChannelSize)
1208-
12091199
if err := vm.Initialize(
12101200
context.TODO(),
12111201
ctx.Context,
12121202
vmDB,
12131203
genesisData,
12141204
chainConfig.Upgrade,
12151205
chainConfig.Config,
1216-
msgChan,
12171206
fxs,
12181207
messageSender,
12191208
); err != nil {
@@ -1277,8 +1266,8 @@ func (m *manager) createSnowmanChain(
12771266
// Asynchronously passes messages from the network to the consensus engine
12781267
h, err := handler.New(
12791268
ctx,
1269+
vm,
12801270
vdrs,
1281-
msgChan,
12821271
m.FrontierPollFrequency,
12831272
m.ConsensusAppConcurrency,
12841273
m.ResourceTracker,

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ require (
1313
github.com/DataDog/zstd v1.5.2
1414
github.com/StephenButtolph/canoto v0.15.0
1515
github.com/antithesishq/antithesis-sdk-go v0.3.8
16-
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250610170140-2fcf45f828a2
16+
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250616171632-973a9f30d630
1717
github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60
18-
github.com/ava-labs/libevm v0.0.0-20250610142802-2672fbd7cdfc
18+
github.com/ava-labs/libevm v1.13.14-0.2.0.release
1919
github.com/btcsuite/btcd/btcutil v1.1.3
2020
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
2121
github.com/compose-spec/compose-go v1.20.2

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl
6666
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
6767
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
6868
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
69-
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250610170140-2fcf45f828a2 h1:/E1w2S6xvEhkO2+C9sGCV8W80qaeSN5WBFqdKLl12HM=
70-
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250610170140-2fcf45f828a2/go.mod h1:cqwBag+zzqifDutdPVzZKovfC2d0L8Zxq4YgTGaMCwg=
69+
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250616171632-973a9f30d630 h1:9QpJ17vK5RGrU4XwN8Xj2iJ2NrGNlPOSINrv0sFxh0U=
70+
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250616171632-973a9f30d630/go.mod h1:gz03IIszWMvTJZHO55Qb+vJgW7gsrPK/AuT2aygpH3c=
7171
github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0=
7272
github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo=
73-
github.com/ava-labs/libevm v0.0.0-20250610142802-2672fbd7cdfc h1:cSXaUY4hdmoJ2FJOgOzn+WiovN/ZB/zkNRgnZhE50OA=
74-
github.com/ava-labs/libevm v0.0.0-20250610142802-2672fbd7cdfc/go.mod h1:+Iol+sVQ1KyoBsHf3veyrBmHCXr3xXRWq6ZXkgVfNLU=
73+
github.com/ava-labs/libevm v1.13.14-0.2.0.release h1:uKGCc5/ceeBbfAPRVtBUxbQt50WzB2pEDb8Uy93ePgQ=
74+
github.com/ava-labs/libevm v1.13.14-0.2.0.release/go.mod h1:+Iol+sVQ1KyoBsHf3veyrBmHCXr3xXRWq6ZXkgVfNLU=
7575
github.com/ava-labs/simplex v0.0.0-20250611154800-78b82e9820e5 h1:rwPm63i5nJ2XIuNjO2H68gDmMKje0VW7orLZMISPrC8=
7676
github.com/ava-labs/simplex v0.0.0-20250611154800-78b82e9820e5/go.mod h1:GVzumIo3zR23/qGRN2AdnVkIPHcKMq/D89EGWZfMGQ0=
7777
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=

proto/messenger/messenger.proto

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package messenger;
55
option go_package = "github.com/ava-labs/avalanchego/proto/pb/messenger";
66

77
service Messenger {
8-
rpc Notify(NotifyRequest) returns (NotifyResponse);
8+
rpc Notify(stream Event) returns (stream EventRequest);
99
}
1010

1111
enum Message {
@@ -14,8 +14,13 @@ enum Message {
1414
MESSAGE_STATE_SYNC_FINISHED = 2;
1515
}
1616

17-
message NotifyRequest {
18-
Message message = 1;
17+
message EventRequest {
18+
oneof event {
19+
bool start = 1;
20+
bool stop = 2;
21+
}
1922
}
2023

21-
message NotifyResponse {}
24+
message Event {
25+
Message message = 1;
26+
}

proto/pb/messenger/messenger.pb.go

Lines changed: 97 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)