Skip to content

Commit d09f8a3

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 <[email protected]>
1 parent 1a40195 commit d09f8a3

File tree

77 files changed

+1642
-707
lines changed

Some content is hidden

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

77 files changed

+1642
-707
lines changed

chains/linearizable_vm.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ 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
}
@@ -47,7 +46,6 @@ func (vm *initializeOnLinearizeVM) Linearize(ctx context.Context, stopVertexID i
4746
vm.genesisBytes,
4847
vm.upgradeBytes,
4948
vm.configBytes,
50-
vm.toEngine,
5149
vm.fxs,
5250
vm.appSender,
5351
)
@@ -74,9 +72,8 @@ func (vm *linearizeOnInitializeVM) Initialize(
7472
_ []byte,
7573
_ []byte,
7674
_ []byte,
77-
toEngine chan<- common.Message,
7875
_ []*common.Fx,
7976
_ common.AppSender,
8077
) error {
81-
return vm.Linearize(ctx, vm.stopVertexID, toEngine)
78+
return vm.Linearize(ctx, vm.stopVertexID)
8279
}

chains/manager.go

Lines changed: 0 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
}
@@ -886,7 +880,6 @@ func (m *manager) createAvalancheChain(
886880
h, err := handler.New(
887881
ctx,
888882
vdrs,
889-
msgChan,
890883
m.FrontierPollFrequency,
891884
m.ConsensusAppConcurrency,
892885
m.ResourceTracker,
@@ -1202,18 +1195,13 @@ func (m *manager) createSnowmanChain(
12021195
vm = tracedvm.NewBlockVM(vm, "proposervm", m.Tracer)
12031196
}
12041197

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-
12091198
if err := vm.Initialize(
12101199
context.TODO(),
12111200
ctx.Context,
12121201
vmDB,
12131202
genesisData,
12141203
chainConfig.Upgrade,
12151204
chainConfig.Config,
1216-
msgChan,
12171205
fxs,
12181206
messageSender,
12191207
); err != nil {
@@ -1278,7 +1266,6 @@ func (m *manager) createSnowmanChain(
12781266
h, err := handler.New(
12791267
ctx,
12801268
vdrs,
1281-
msgChan,
12821269
m.FrontierPollFrequency,
12831270
m.ConsensusAppConcurrency,
12841271
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.20250612190710-93f19a90ac3d
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.20250612190710-93f19a90ac3d h1:o00/MqnOlQy/OlsPSmL4toLTXeaMiwOLGjwCL087hws=
70+
github.com/ava-labs/coreth v0.15.2-rc.0.0.20250612190710-93f19a90ac3d/go.mod h1:HoNW7SkTMj25uOhT3QIDOh4I1g0a2lcKv4992g1/Z+g=
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/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
7676
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
7777
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=

proto/messenger/messenger.proto

Lines changed: 10 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,14 @@ 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+
}
22+
uint64 p_chain_height = 3;
1923
}
2024

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

proto/pb/messenger/messenger.pb.go

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

0 commit comments

Comments
 (0)