Skip to content

Commit a2054eb

Browse files
committed
Remove IsPrague helper in favor of timestamp-based Pectra upgrage
1 parent 901dc8f commit a2054eb

16 files changed

Lines changed: 335 additions & 135 deletions

api/debug.go

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
gethTypes "github.com/onflow/go-ethereum/core/types"
1515
"github.com/onflow/go-ethereum/eth/tracers"
1616
"github.com/onflow/go-ethereum/eth/tracers/logger"
17+
gethParams "github.com/onflow/go-ethereum/params"
1718
"github.com/onflow/go-ethereum/rpc"
1819
"github.com/rs/zerolog"
1920

@@ -44,15 +45,16 @@ type txTraceResult struct {
4445
}
4546

4647
type DebugAPI struct {
47-
registerStore *pebble.RegisterStorage
48-
logger zerolog.Logger
49-
tracer storage.TraceIndexer
50-
blocks storage.BlockIndexer
51-
transactions storage.TransactionIndexer
52-
receipts storage.ReceiptIndexer
53-
client *requester.CrossSporkClient
54-
config config.Config
55-
rateLimiter RateLimiter
48+
registerStore *pebble.RegisterStorage
49+
logger zerolog.Logger
50+
tracer storage.TraceIndexer
51+
blocks storage.BlockIndexer
52+
transactions storage.TransactionIndexer
53+
receipts storage.ReceiptIndexer
54+
client *requester.CrossSporkClient
55+
config config.Config
56+
rateLimiter RateLimiter
57+
evmChainConfig *gethParams.ChainConfig
5658
}
5759

5860
func NewDebugAPI(
@@ -66,16 +68,19 @@ func NewDebugAPI(
6668
logger zerolog.Logger,
6769
rateLimiter RateLimiter,
6870
) *DebugAPI {
71+
evmChainConfig := emulator.MakeChainConfig(config.EVMNetworkID)
72+
6973
return &DebugAPI{
70-
registerStore: registerStore,
71-
logger: logger,
72-
tracer: tracer,
73-
blocks: blocks,
74-
transactions: transactions,
75-
receipts: receipts,
76-
client: client,
77-
config: config,
78-
rateLimiter: rateLimiter,
74+
registerStore: registerStore,
75+
logger: logger,
76+
tracer: tracer,
77+
blocks: blocks,
78+
transactions: transactions,
79+
receipts: receipts,
80+
client: client,
81+
config: config,
82+
rateLimiter: rateLimiter,
83+
evmChainConfig: evmChainConfig,
7984
}
8085
}
8186

@@ -148,17 +153,17 @@ func (d *DebugAPI) TraceCall(
148153
config = &tracers.TraceCallConfig{}
149154
}
150155

151-
height, err := resolveBlockTag(&blockNrOrHash, d.blocks, d.logger)
156+
tracer, err := d.tracerForReceipt(&config.TraceConfig, nil)
152157
if err != nil {
153158
return nil, err
154159
}
155160

156-
block, err := d.blocks.GetByHeight(height)
161+
height, err := resolveBlockTag(&blockNrOrHash, d.blocks, d.logger)
157162
if err != nil {
158163
return nil, err
159164
}
160165

161-
tracer, err := d.tracerForReceipt(&config.TraceConfig, block.Timestamp, nil)
166+
block, err := d.blocks.GetByHeight(height)
162167
if err != nil {
163168
return nil, err
164169
}
@@ -310,7 +315,7 @@ func (d *DebugAPI) traceTransaction(
310315
return nil, err
311316
}
312317

313-
tracer, err := d.tracerForReceipt(config, block.Timestamp, receipt)
318+
tracer, err := d.tracerForReceipt(config, receipt)
314319
if err != nil {
315320
return nil, err
316321
}
@@ -398,7 +403,7 @@ func (d *DebugAPI) traceBlockByNumber(
398403
return nil, err
399404
}
400405

401-
tracer, err := d.tracerForReceipt(config, block.Timestamp, receipt)
406+
tracer, err := d.tracerForReceipt(config, receipt)
402407
if err != nil {
403408
return nil, err
404409
}
@@ -439,17 +444,16 @@ func (d *DebugAPI) executorAtBlock(block *models.Block) (*evm.BlockExecutor, err
439444
}
440445

441446
func (d *DebugAPI) tracerForReceipt(
442-
traceConfig *tracers.TraceConfig,
443-
evmBlockTimestamp uint64,
447+
config *tracers.TraceConfig,
444448
receipt *models.Receipt,
445449
) (*tracers.Tracer, error) {
446-
if traceConfig == nil {
447-
traceConfig = &tracers.TraceConfig{}
450+
if config == nil {
451+
config = &tracers.TraceConfig{}
448452
}
449453

450454
// Default tracer is the struct logger
451-
if traceConfig.Tracer == nil {
452-
logger := logger.NewStructLogger(traceConfig.Config)
455+
if config.Tracer == nil {
456+
logger := logger.NewStructLogger(config.Config)
453457
return &tracers.Tracer{
454458
Hooks: logger.Hooks(),
455459
GetResult: logger.GetResult,
@@ -467,16 +471,11 @@ func (d *DebugAPI) tracerForReceipt(
467471
}
468472
}
469473

470-
evmChainConfig := emulator.MakeChainConfig(d.config.EVMNetworkID)
471-
if !config.IsPrague(evmBlockTimestamp, d.config.FlowNetworkID) {
472-
evmChainConfig.PragueTime = nil
473-
}
474-
475474
return tracers.DefaultDirectory.New(
476-
*traceConfig.Tracer,
475+
*config.Tracer,
477476
tracerCtx,
478-
traceConfig.TracerConfig,
479-
evmChainConfig,
477+
config.TracerConfig,
478+
d.evmChainConfig,
480479
)
481480
}
482481

bootstrap/bootstrap.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,17 @@ func (b *Bootstrap) StartEventIngestion(ctx context.Context) error {
162162
nextCadenceHeight,
163163
)
164164

165-
callTracerCollector := replayer.NewCallTracerCollector(
166-
b.config,
165+
callTracerCollector, err := replayer.NewCallTracerCollector(
166+
b.config.EVMNetworkID,
167167
b.logger,
168168
)
169+
if err != nil {
170+
return err
171+
}
169172
blocksProvider := replayer.NewBlocksProvider(
170173
b.storages.Blocks,
171174
chainID,
175+
callTracerCollector.TxTracer(),
172176
)
173177
replayerConfig := replayer.Config{
174178
ChainID: chainID,

config/config.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/onflow/flow-go-sdk"
1010
"github.com/onflow/flow-go-sdk/crypto"
1111
flowGoKMS "github.com/onflow/flow-go-sdk/crypto/cloudkms"
12-
"github.com/onflow/flow-go/fvm/evm/emulator"
1312
flowGo "github.com/onflow/flow-go/model/flow"
1413
"github.com/onflow/go-ethereum/common"
1514
"github.com/rs/zerolog"
@@ -24,25 +23,6 @@ const EmulatorInitCadenceHeight = uint64(0)
2423
// We don't use 0 as it has a special meaning to represent latest block in the AN API context.
2524
const LiveNetworkInitCadenceHeight = uint64(1)
2625

27-
// IsPrague determines if the Prague hard-fork is active for a given EVM block timestamp
28-
// on the specified Flow network. The Prague hard-fork introduces several EVM features
29-
// including EIP-7702 and other Pectra updates.
30-
//
31-
// Returns:
32-
// - true if the block height is at or after the Prague activation height for the network
33-
// - false if the block height is before the Prague activation height
34-
// - true for networks other than testnet/mainnet (development, emulator, etc.)
35-
func IsPrague(blockTimestamp uint64, chainID flowGo.ChainID) bool {
36-
switch chainID {
37-
case flowGo.Testnet:
38-
return blockTimestamp >= emulator.TestnetPragueActivation
39-
case flowGo.Mainnet:
40-
return blockTimestamp >= emulator.MainnetPragueActivation
41-
default:
42-
return true // Prague is always enabled for development/emulator environments
43-
}
44-
}
45-
4626
type TxStateValidation string
4727

4828
const (

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/holiman/uint256 v1.3.2
1212
github.com/onflow/atree v0.10.0
1313
github.com/onflow/cadence v1.3.4
14-
github.com/onflow/flow-go v0.40.0-rc.0.0.20250425162205-8941ed6c5e9a
14+
github.com/onflow/flow-go v0.40.0-rc.0.0.20250428095609-50a461f1df3f
1515
github.com/onflow/flow-go-sdk v1.3.3
1616
github.com/onflow/go-ethereum v1.15.9
1717
github.com/prometheus/client_golang v1.20.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ github.com/onflow/flow-ft/lib/go/contracts v1.0.1 h1:Ts5ob+CoCY2EjEd0W6vdLJ7hLL3
563563
github.com/onflow/flow-ft/lib/go/contracts v1.0.1/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
564564
github.com/onflow/flow-ft/lib/go/templates v1.0.1 h1:FDYKAiGowABtoMNusLuRCILIZDtVqJ/5tYI4VkF5zfM=
565565
github.com/onflow/flow-ft/lib/go/templates v1.0.1/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE=
566-
github.com/onflow/flow-go v0.40.0-rc.0.0.20250425162205-8941ed6c5e9a h1:Q9wWmGSDNyfKMFJd2z0wPUvhtaONdwh1vIh+M9zz8gY=
567-
github.com/onflow/flow-go v0.40.0-rc.0.0.20250425162205-8941ed6c5e9a/go.mod h1:63N8d/MswUsPtvJKbhBKzXrHmugZWDDC9WQ9nuR2V5U=
566+
github.com/onflow/flow-go v0.40.0-rc.0.0.20250428095609-50a461f1df3f h1:V6u2K8XHWSd7jQ1iBnE/kuff2hBJCsYNKN7LQNcQvtM=
567+
github.com/onflow/flow-go v0.40.0-rc.0.0.20250428095609-50a461f1df3f/go.mod h1:63N8d/MswUsPtvJKbhBKzXrHmugZWDDC9WQ9nuR2V5U=
568568
github.com/onflow/flow-go-sdk v1.3.3 h1:wj7llql3wesQYBePh3lEFI+jk3Df1sa13bRsL139JDo=
569569
github.com/onflow/flow-go-sdk v1.3.3/go.mod h1:tSLvYIac9DlmUEqKHSHbVRyv4mSB0va4AuiV3XB9ENc=
570570
github.com/onflow/flow-nft/lib/go/contracts v1.2.4 h1:gWJgSSgIGo0qWOqr90+khQ69VoYF9vNlqzF+Yh6YYy4=

services/evm/executor.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/onflow/go-ethereum/eth/tracers"
1515
"github.com/rs/zerolog"
1616

17-
"github.com/onflow/flow-evm-gateway/config"
1817
"github.com/onflow/flow-evm-gateway/models"
1918
"github.com/onflow/flow-evm-gateway/storage"
2019
)
@@ -143,7 +142,6 @@ func (s *BlockExecutor) blockContext(
143142
return types.BlockContext{}, err
144143
}
145144

146-
ctx.IsPrague = config.IsPrague(s.block.Timestamp, s.chainID)
147145
ctx.TxCountSoFar = s.txIndex
148146
ctx.TotalGasUsedSoFar = s.gasUsed
149147

services/ingestion/engine.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,19 +236,13 @@ func (e *Engine) indexEvents(events *models.CadenceEvents, batch *pebbleDB.Batch
236236
return err
237237
}
238238

239-
traceCollector := e.replayerConfig.CallTracerCollector
240-
txTracer, err := traceCollector.TxTracer(events.Block().Timestamp)
241-
if err != nil {
242-
return err
243-
}
244-
245239
replayer := sync.NewReplayer(
246240
e.replayerConfig.ChainID,
247241
e.replayerConfig.RootAddr,
248242
e.registerStore,
249243
e.blocksProvider,
250244
e.log,
251-
txTracer,
245+
e.replayerConfig.CallTracerCollector.TxTracer(),
252246
e.replayerConfig.ValidateResults,
253247
)
254248

@@ -299,6 +293,7 @@ func (e *Engine) indexEvents(events *models.CadenceEvents, batch *pebbleDB.Batch
299293
return fmt.Errorf("failed to index receipts for block %d event: %w", events.Block().Height, err)
300294
}
301295

296+
traceCollector := e.replayerConfig.CallTracerCollector
302297
for _, tx := range events.Transactions() {
303298
txHash := tx.Hash()
304299
traceResult, err := traceCollector.Collect(txHash)

services/ingestion/engine_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestSerialBlockIngestion(t *testing.T) {
6666

6767
engine := NewEventIngestionEngine(
6868
subscriber,
69-
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
69+
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
7070
store,
7171
registerStore,
7272
blocks,
@@ -145,7 +145,7 @@ func TestSerialBlockIngestion(t *testing.T) {
145145

146146
engine := NewEventIngestionEngine(
147147
subscriber,
148-
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
148+
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
149149
store,
150150
registerStore,
151151
blocks,
@@ -266,7 +266,7 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
266266

267267
engine := NewEventIngestionEngine(
268268
subscriber,
269-
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
269+
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
270270
store,
271271
registerStore,
272272
blocks,
@@ -374,7 +374,7 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
374374

375375
engine := NewEventIngestionEngine(
376376
subscriber,
377-
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
377+
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
378378
store,
379379
registerStore,
380380
blocks,
@@ -468,7 +468,7 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
468468

469469
engine := NewEventIngestionEngine(
470470
subscriber,
471-
replayer.NewBlocksProvider(blocks, flowGo.Emulator),
471+
replayer.NewBlocksProvider(blocks, flowGo.Emulator, nil),
472472
store,
473473
registerStore,
474474
blocks,

services/replayer/blocks_provider.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package replayer
33
import (
44
"fmt"
55

6-
"github.com/onflow/flow-evm-gateway/config"
76
"github.com/onflow/flow-evm-gateway/models"
87
"github.com/onflow/flow-evm-gateway/storage"
98
"github.com/onflow/flow-go/fvm/evm/offchain/blocks"
109
evmTypes "github.com/onflow/flow-go/fvm/evm/types"
1110
flowGo "github.com/onflow/flow-go/model/flow"
1211
gethCommon "github.com/onflow/go-ethereum/common"
12+
"github.com/onflow/go-ethereum/eth/tracers"
1313
)
1414

1515
type blockSnapshot struct {
@@ -20,7 +20,7 @@ type blockSnapshot struct {
2020
var _ evmTypes.BlockSnapshot = (*blockSnapshot)(nil)
2121

2222
func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
23-
blockContext, err := blocks.NewBlockContext(
23+
return blocks.NewBlockContext(
2424
bs.chainID,
2525
bs.block.Height,
2626
bs.block.Timestamp,
@@ -37,15 +37,8 @@ func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
3737
return blockHash
3838
},
3939
bs.block.PrevRandao,
40-
nil, // Set by the sync.ReplayBlockExecution method
40+
bs.tracer,
4141
)
42-
if err != nil {
43-
return evmTypes.BlockContext{}, err
44-
}
45-
46-
blockContext.IsPrague = config.IsPrague(bs.block.Timestamp, bs.chainID)
47-
48-
return blockContext, nil
4942
}
5043

5144
// This BlocksProvider implementation is used in the EVM events ingestion pipeline.
@@ -58,6 +51,7 @@ func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
5851
type BlocksProvider struct {
5952
blocks storage.BlockIndexer
6053
chainID flowGo.ChainID
54+
tracer *tracers.Tracer
6155
latestBlock *models.Block
6256
}
6357

@@ -66,10 +60,12 @@ var _ evmTypes.BlockSnapshotProvider = (*BlocksProvider)(nil)
6660
func NewBlocksProvider(
6761
blocks storage.BlockIndexer,
6862
chainID flowGo.ChainID,
63+
tracer *tracers.Tracer,
6964
) *BlocksProvider {
7065
return &BlocksProvider{
7166
blocks: blocks,
7267
chainID: chainID,
68+
tracer: tracer,
7369
}
7470
}
7571

0 commit comments

Comments
 (0)