Skip to content

Commit e5992f3

Browse files
authored
Merge branch 'mpeter/poc-index-finalized-block-results' into feature/pectra-upgrade
2 parents 237faaa + c00b0f7 commit e5992f3

11 files changed

Lines changed: 969 additions & 16 deletions

File tree

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ e2e-test:
7878

7979
.PHONY: check-tidy
8080
check-tidy:
81-
go mod tidy
82-
git diff --exit-code
83-
cd tests
84-
go mod tidy
81+
go mod tidy -v
82+
cd tests; go mod tidy -v
8583
git diff --exit-code
8684

8785
.PHONY: build

bootstrap/bootstrap.go

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Storages struct {
5757
Transactions storage.TransactionIndexer
5858
Receipts storage.ReceiptIndexer
5959
Traces storage.TraceIndexer
60+
EventsHash *pebble.EventsHash
6061
}
6162

6263
type Publishers struct {
@@ -154,13 +155,36 @@ func (b *Bootstrap) StartEventIngestion(ctx context.Context) error {
154155
}
155156

156157
// create event subscriber
157-
subscriber := ingestion.NewRPCEventSubscriber(
158-
b.logger,
159-
b.client,
160-
chainID,
161-
b.keystore,
162-
nextCadenceHeight,
163-
)
158+
var subscriber ingestion.EventSubscriber
159+
if b.config.ExperimentalSoftFinalityEnabled {
160+
var verifier *ingestion.SealingVerifier
161+
if b.config.ExperimentalSealingVerificationEnabled {
162+
verifier = ingestion.NewSealingVerifier(
163+
b.logger,
164+
b.client,
165+
chainID,
166+
b.storages.EventsHash,
167+
nextCadenceHeight,
168+
)
169+
}
170+
171+
subscriber = ingestion.NewRPCBlockTrackingSubscriber(
172+
b.logger,
173+
b.client,
174+
chainID,
175+
b.keystore,
176+
nextCadenceHeight,
177+
verifier,
178+
)
179+
} else {
180+
subscriber = ingestion.NewRPCEventSubscriber(
181+
b.logger,
182+
b.client,
183+
chainID,
184+
b.keystore,
185+
nextCadenceHeight,
186+
)
187+
}
164188

165189
callTracerCollector, err := replayer.NewCallTracerCollector(
166190
b.config.EVMNetworkID,
@@ -566,6 +590,7 @@ func setupStorage(
566590
blocks := pebble.NewBlocks(store, config.FlowNetworkID)
567591
storageAddress := evm.StorageAccountAddress(config.FlowNetworkID)
568592
registerStore := pebble.NewRegisterStorage(store, storageAddress)
593+
eventsHash := pebble.NewEventsHash(store)
569594

570595
batch := store.NewBatch()
571596
defer func() {
@@ -580,7 +605,17 @@ func setupStorage(
580605
if config.ForceStartCadenceHeight != 0 {
581606
logger.Warn().Uint64("height", config.ForceStartCadenceHeight).Msg("force setting starting Cadence height!!!")
582607
if err := blocks.SetLatestCadenceHeight(config.ForceStartCadenceHeight, batch); err != nil {
583-
return nil, nil, err
608+
return nil, nil, fmt.Errorf("failed to set latest cadence height: %w", err)
609+
}
610+
611+
verifiedHeight, err := eventsHash.ProcessedSealedHeight()
612+
if err != nil && !errors.Is(err, errs.ErrStorageNotInitialized) {
613+
return nil, nil, fmt.Errorf("failed to get latest verified sealed height: %w", err)
614+
}
615+
if verifiedHeight > config.ForceStartCadenceHeight {
616+
if err := eventsHash.SetProcessedSealedHeight(config.ForceStartCadenceHeight); err != nil {
617+
return nil, nil, fmt.Errorf("failed to set latest verified sealed height: %w", err)
618+
}
584619
}
585620
}
586621

@@ -645,6 +680,7 @@ func setupStorage(
645680
Transactions: pebble.NewTransactions(store),
646681
Receipts: pebble.NewReceipts(store),
647682
Traces: pebble.NewTraces(store),
683+
EventsHash: eventsHash,
648684
}, nil
649685
}
650686

cmd/run/cmd.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ func parseConfigFromFlags() error {
223223
return fmt.Errorf("unknown tx state validation: %s", txStateValidation)
224224
}
225225

226+
cfg.ExperimentalSoftFinalityEnabled = experimentalSoftFinalityEnabled
227+
cfg.ExperimentalSealingVerificationEnabled = experimentalSealingVerificationEnabled
228+
226229
return nil
227230
}
228231

@@ -246,6 +249,9 @@ var (
246249
txStateValidation string
247250
initHeight,
248251
forceStartHeight uint64
252+
253+
experimentalSoftFinalityEnabled,
254+
experimentalSealingVerificationEnabled bool
249255
)
250256

251257
func init() {
@@ -283,4 +289,6 @@ func init() {
283289
Cmd.Flags().StringVar(&txStateValidation, "tx-state-validation", "tx-seal", "Sets the transaction validation mechanism. It can validate using the local state index, or wait for the outer Flow transaction to seal. Available values ('local-index' / 'tx-seal'), defaults to 'tx-seal'.")
284290
Cmd.Flags().Uint64Var(&cfg.TxRequestLimit, "tx-request-limit", 0, "Number of transaction submissions to allow per the specified interval.")
285291
Cmd.Flags().DurationVar(&cfg.TxRequestLimitDuration, "tx-request-limit-duration", time.Second*3, "Time interval upon which to enforce transaction submission rate limiting.")
292+
Cmd.Flags().BoolVar(&experimentalSoftFinalityEnabled, "experimental-soft-finality-enabled", false, "Sets whether the gateway should use the experimental soft finality feature. WARNING: This may result in incorrect results being returned in certain circumstances. Use only if you know what you are doing.")
293+
Cmd.Flags().BoolVar(&experimentalSealingVerificationEnabled, "experimental-sealing-verification-enabled", true, "Sets whether the gateway should use the experimental soft finality sealing verification feature. WARNING: This may result in indexing halts if events do not match. Use only if you know what you are doing.")
286294
}

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,13 @@ type Config struct {
9696
// TxRequestLimitDuration is the time interval upon which to enforce transaction submission
9797
// rate limiting.
9898
TxRequestLimitDuration time.Duration
99+
// ExperimentalSoftFinalityEnabled enables the experimental soft finality feature which syncs
100+
// EVM block and transaction data from the upstream Access node before the block is sealed.
101+
// CAUTION: This feature is experimental and may return incorrect data in certain circumstances.
102+
ExperimentalSoftFinalityEnabled bool
103+
// ExperimentalSealingVerificationEnabled enables the experimental sealing verification feature
104+
// which verifies the hash of the EVM events ingested by the requester engine match the hash
105+
// of the events from the sealed block in the Flow network.
106+
// CAUTION: This feature is experimental and will cause the node to halt if the events don't match.
107+
ExperimentalSealingVerificationEnabled bool
99108
}

0 commit comments

Comments
 (0)