Skip to content

Commit 8fc5805

Browse files
authored
Capture & index events during bootstrapping (#870)
* Capture & index events during bootstrapping * Add comments describing the included events during the genesis block commit
1 parent 1e78e87 commit 8fc5805

File tree

4 files changed

+52
-25
lines changed

4 files changed

+52
-25
lines changed

emulator/blockchain.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,22 +716,25 @@ func configureNewLedger(
716716
return nil, nil, err
717717
}
718718

719-
genesisExecutionSnapshot, err := bootstrapLedger(vm, ctx, ledger, conf)
719+
genesisExecutionSnapshot, output, err := bootstrapLedger(vm, ctx, ledger, conf)
720720
if err != nil {
721721
return nil, nil, fmt.Errorf("failed to bootstrap execution state: %w", err)
722722
}
723723

724724
// commit the genesis block to storage
725725
genesis := Genesis(conf.GetChainID())
726-
726+
// The `output.Events` slice contains only EVM-related events emitted
727+
// during the VM bridge bootstrap. This is needed for the proper
728+
// setup of the EVM Gateway, since missing events will cause state
729+
// mismatch, preventing the service to run.
727730
err = store.CommitBlock(
728731
context.Background(),
729732
*genesis,
730733
nil,
731734
nil,
732735
nil,
733736
genesisExecutionSnapshot,
734-
nil,
737+
output.Events,
735738
)
736739
if err != nil {
737740
return nil, nil, err
@@ -772,6 +775,7 @@ func bootstrapLedger(
772775
conf config,
773776
) (
774777
*snapshot.ExecutionSnapshot,
778+
fvm.ProcedureOutput,
775779
error,
776780
) {
777781
accountKey := conf.GetServiceKey().AccountKey()
@@ -796,14 +800,14 @@ func bootstrapLedger(
796800

797801
executionSnapshot, output, err := vm.Run(ctx, bootstrap, ledger)
798802
if err != nil {
799-
return nil, err
803+
return nil, fvm.ProcedureOutput{}, err
800804
}
801805

802806
if output.Err != nil {
803-
return nil, output.Err
807+
return nil, fvm.ProcedureOutput{}, output.Err
804808
}
805809

806-
return executionSnapshot, nil
810+
return executionSnapshot, output, nil
807811
}
808812

809813
func configureBootstrapProcedure(conf config, flowAccountKey flowgo.AccountPublicKey, supply cadence.UFix64) *fvm.BootstrapProcedure {

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ require (
1212
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
1313
github.com/improbable-eng/grpc-web v0.15.0
1414
github.com/logrusorgru/aurora v2.0.3+incompatible
15-
github.com/onflow/cadence v1.7.0
15+
github.com/onflow/cadence v1.7.1
1616
github.com/onflow/crypto v0.25.3
1717
github.com/onflow/flow-core-contracts/lib/go/templates v1.9.0
18-
github.com/onflow/flow-go v0.43.1-rc.1.0.20250924183344-715803471569
19-
github.com/onflow/flow-go-sdk v1.8.2
18+
github.com/onflow/flow-go v0.43.1-rc.5-pr8007.0.20251007165614-c6967df18fa9
19+
github.com/onflow/flow-go-sdk v1.8.4
2020
github.com/onflow/flow-nft/lib/go/contracts v1.3.0
21-
github.com/onflow/flow/protobuf/go/flow v0.4.15
21+
github.com/onflow/flow/protobuf/go/flow v0.4.16
2222
github.com/prometheus/client_golang v1.23.2
2323
github.com/psiemens/graceland v1.0.0
2424
github.com/psiemens/sconfig v0.1.0
@@ -74,6 +74,7 @@ require (
7474
github.com/ferranbt/fastssz v0.1.4 // indirect
7575
github.com/fsnotify/fsnotify v1.6.0 // indirect
7676
github.com/fxamacker/circlehash v0.3.0 // indirect
77+
github.com/fxamacker/golang-lru/v2 v2.0.0-20250716153046-22c8d17dc4ee // indirect
7778
github.com/getsentry/sentry-go v0.27.0 // indirect
7879
github.com/go-kit/kit v0.12.0 // indirect
7980
github.com/go-kit/log v0.2.1 // indirect
@@ -155,7 +156,7 @@ require (
155156
github.com/onflow/wal v1.0.2 // indirect
156157
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
157158
github.com/pelletier/go-toml/v2 v2.2.1 // indirect
158-
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
159+
github.com/pierrec/lz4/v4 v4.1.22 // indirect
159160
github.com/pion/dtls/v2 v2.2.12 // indirect
160161
github.com/pion/logging v0.2.2 // indirect
161162
github.com/pion/stun/v2 v2.0.0 // indirect

go.sum

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6l
9898
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
9999
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
100100
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
101-
github.com/aws/aws-sdk-go-v2 v1.39.0 h1:xm5WV/2L4emMRmMjHFykqiA4M/ra0DJVSWUkDyBjbg4=
102-
github.com/aws/aws-sdk-go-v2 v1.39.0/go.mod h1:sDioUELIUO9Znk23YVmIk86/9DOpkbyyVb1i/gUNFXY=
101+
github.com/aws/aws-sdk-go-v2 v1.39.1 h1:fWZhGAwVRK/fAN2tmt7ilH4PPAE11rDj7HytrmbZ2FE=
102+
github.com/aws/aws-sdk-go-v2 v1.39.1/go.mod h1:sDioUELIUO9Znk23YVmIk86/9DOpkbyyVb1i/gUNFXY=
103103
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.1 h1:VGkV9KmhGqOQWnHyi4gLG98kE6OecT42fdrCGFWxJsc=
104104
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.5.1/go.mod h1:PLlnMiki//sGnCJiW+aVpvP/C8Kcm8mEj/IVm9+9qk4=
105105
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 h1:oegbebPEMA/1Jny7kvwejowCaHz1FWZAQ94WXFNCyTM=
@@ -288,6 +288,8 @@ github.com/fxamacker/cbor/v2 v2.8.1-0.20250402194037-6f932b086829 h1:qOglMkJ5YBw
288288
github.com/fxamacker/cbor/v2 v2.8.1-0.20250402194037-6f932b086829/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
289289
github.com/fxamacker/circlehash v0.3.0 h1:XKdvTtIJV9t7DDUtsf0RIpC1OcxZtPbmgIH7ekx28WA=
290290
github.com/fxamacker/circlehash v0.3.0/go.mod h1:3aq3OfVvsWtkWMb6A1owjOQFA+TLsD5FgJflnaQwtMM=
291+
github.com/fxamacker/golang-lru/v2 v2.0.0-20250716153046-22c8d17dc4ee h1:9RFHOj6xUdQRi1lz/BJXwi0IloXtv6Y2tp7rdSC7SQk=
292+
github.com/fxamacker/golang-lru/v2 v2.0.0-20250716153046-22c8d17dc4ee/go.mod h1:1FYBKLDzpfjjoWMTK1cIOxsTomg/n35DWNLu6FoYEb8=
291293
github.com/gabriel-vasile/mimetype v1.4.6 h1:3+PzJTKLkvgjeTbts6msPJt4DixhT4YtFNf1gtGe3zc=
292294
github.com/gabriel-vasile/mimetype v1.4.6/go.mod h1:JX1qVKqZd40hUPpAfiNTe0Sne7hdfKSbOqqmkq8GCXc=
293295
github.com/gammazero/deque v1.0.0 h1:LTmimT8H7bXkkCy6gZX7zNLtkbz4NdS2z8LZuor3j34=
@@ -747,8 +749,8 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N
747749
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
748750
github.com/onflow/atree v0.10.1 h1:8sixWP3l3LitcyuKkVepbIsLbfr7JN3cCB/iA1j2JD8=
749751
github.com/onflow/atree v0.10.1/go.mod h1:+BuiL0XuIigHJqwkdIuDNzxXvyDx1jYUog/w+iZhcE8=
750-
github.com/onflow/cadence v1.7.0 h1:bbxl9Hy3w3RuigO9higtecqqeqOAHzGMrA6AI8dDSUk=
751-
github.com/onflow/cadence v1.7.0/go.mod h1:1lKdLNVHIoO0jEjkRPMtOmBWYCG1An9TXSoiCuGIIpo=
752+
github.com/onflow/cadence v1.7.1 h1:VpPiC13e4qrdpyqaagd+dpHtQwfJ/djr97FgT3SovWA=
753+
github.com/onflow/cadence v1.7.1/go.mod h1:1lKdLNVHIoO0jEjkRPMtOmBWYCG1An9TXSoiCuGIIpo=
752754
github.com/onflow/crypto v0.25.3 h1:XQ3HtLsw8h1+pBN+NQ1JYM9mS2mVXTyg55OldaAIF7U=
753755
github.com/onflow/crypto v0.25.3/go.mod h1:+1igaXiK6Tjm9wQOBD1EGwW7bYWMUGKtwKJ/2QL/OWs=
754756
github.com/onflow/fixed-point v0.1.1 h1:j0jYZVO8VGyk1476alGudEg7XqCkeTVxb5ElRJRKS90=
@@ -763,16 +765,16 @@ github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3
763765
github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
764766
github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM=
765767
github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE=
766-
github.com/onflow/flow-go v0.43.1-rc.1.0.20250924183344-715803471569 h1:+fi9omYUs55ZyvfIcR2W9FgsmjJy03vIQhiYRUebRwk=
767-
github.com/onflow/flow-go v0.43.1-rc.1.0.20250924183344-715803471569/go.mod h1:i7oxRZWxVV7bhgm6sprx9O1w8bp504i45t7sj5H0Bo8=
768-
github.com/onflow/flow-go-sdk v1.8.2 h1:Jkoh0LdH4kIADFdHoHK31qHcH0QnCkAL+ybjAkBEbqc=
769-
github.com/onflow/flow-go-sdk v1.8.2/go.mod h1:/5g1t+xgk1nFXz8ifk8O3aT4DqLwq5p3k2BhiW4ZX+U=
768+
github.com/onflow/flow-go v0.43.1-rc.5-pr8007.0.20251007165614-c6967df18fa9 h1:PPIDrvyHEzkegSn8sYvQxmnegsiwdwmIrYJBNLSqaGw=
769+
github.com/onflow/flow-go v0.43.1-rc.5-pr8007.0.20251007165614-c6967df18fa9/go.mod h1:pRsxdt8GYriAfP4RjUsCJ505MQcAZgyZq7K4DuWxrXI=
770+
github.com/onflow/flow-go-sdk v1.8.4 h1:WHtVjryOU6ZJx0jUSjBPOrWoGqGDr+eEejyIkfbiBCE=
771+
github.com/onflow/flow-go-sdk v1.8.4/go.mod h1:Jli9sI78LAnoC3OVGeAs0ngOezoLTfE/GrKOAB9TbTw=
770772
github.com/onflow/flow-nft/lib/go/contracts v1.3.0 h1:DmNop+O0EMyicZvhgdWboFG57xz5t9Qp81FKlfKyqJc=
771773
github.com/onflow/flow-nft/lib/go/contracts v1.3.0/go.mod h1:eZ9VMMNfCq0ho6kV25xJn1kXeCfxnkhj3MwF3ed08gY=
772774
github.com/onflow/flow-nft/lib/go/templates v1.3.0 h1:uGIBy4GEY6Z9hKP7sm5nA5kwvbvLWW4nWx5NN9Wg0II=
773775
github.com/onflow/flow-nft/lib/go/templates v1.3.0/go.mod h1:gVbb5fElaOwKhV5UEUjM+JQTjlsguHg2jwRupfM/nng=
774-
github.com/onflow/flow/protobuf/go/flow v0.4.15 h1:7Xt7kkqeeygWMw/S327uKu11FPJghNm1pvam2HXbC7g=
775-
github.com/onflow/flow/protobuf/go/flow v0.4.15/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
776+
github.com/onflow/flow/protobuf/go/flow v0.4.16 h1:UADQeq/mpuqFk+EkwqDNoF70743raWQKmB/Dm/eKt2Q=
777+
github.com/onflow/flow/protobuf/go/flow v0.4.16/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
776778
github.com/onflow/go-ethereum v1.13.4 h1:iNO86fm8RbBbhZ87ZulblInqCdHnAQVY8okBrNsTevc=
777779
github.com/onflow/go-ethereum v1.13.4/go.mod h1:cE/gEUkAffhwbVmMJYz+t1dAfVNHNwZCgc3BWtZxBGY=
778780
github.com/onflow/nft-storefront/lib/go/contracts v1.0.0 h1:sxyWLqGm/p4EKT6DUlQESDG1ZNMN9GjPCm1gTq7NGfc=
@@ -818,8 +820,8 @@ github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h
818820
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
819821
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
820822
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
821-
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
822-
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
823+
github.com/pierrec/lz4/v4 v4.1.22 h1:cKFw6uJDK+/gfw5BcDL0JL5aBsAFdsIT18eRtLj7VIU=
824+
github.com/pierrec/lz4/v4 v4.1.22/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
823825
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
824826
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
825827
github.com/pion/datachannel v1.5.10 h1:ly0Q26K1i6ZkGf42W7D4hQYR90pZwzFOjTq5AuCKk4o=

server/access/streamBackend.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,19 @@ func getExecutionDataFunc(blockchain *emulator.Blockchain) GetExecutionDataFunc
242242
Address: common.Address(blockchain.GetChain().ServiceAddress()),
243243
Name: string(evmEvents.EventTypeBlockExecuted),
244244
}
245+
evmTxExecutedEventType := common.AddressLocation{
246+
Address: common.Address(blockchain.GetChain().ServiceAddress()),
247+
Name: string(evmEvents.EventTypeTransactionExecuted),
248+
}
245249

246-
events, err := blockchain.GetEventsByHeight(
250+
evmTxEvents, err := blockchain.GetEventsByHeight(
251+
height,
252+
evmTxExecutedEventType.ID(),
253+
)
254+
if err != nil {
255+
return nil, err
256+
}
257+
evmBlockEvents, err := blockchain.GetEventsByHeight(
247258
height,
248259
evmBlockExecutedEventType.ID(),
249260
)
@@ -254,9 +265,18 @@ func getExecutionDataFunc(blockchain *emulator.Blockchain) GetExecutionDataFunc
254265
// chunk.
255266
if len(chunks) > 0 {
256267
lastChunk := chunks[len(chunks)-1]
257-
for _, event := range events {
268+
for _, event := range evmBlockEvents {
258269
lastChunk.Events = append(lastChunk.Events, event)
259270
}
271+
} else {
272+
// For the genesis block, where there are no chunks,
273+
// we still want to capture & index the EVM-related
274+
// events, which can occur during bootstrapping.
275+
evmTxEvents = append(evmTxEvents, evmBlockEvents...)
276+
chunk := &execution_data.ChunkExecutionData{
277+
Events: evmTxEvents,
278+
}
279+
chunks = append(chunks, chunk)
260280
}
261281

262282
executionData := &execution_data.BlockExecutionData{

0 commit comments

Comments
 (0)