Skip to content

Commit a404eab

Browse files
committed
Merge remote-tracking branch 'origin/main' into mpeter/poc-index-finalized-block-results
2 parents efd12b0 + d6db057 commit a404eab

23 files changed

Lines changed: 551 additions & 147 deletions

.github/workflows/build.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
name: "Build & Push EVM Gateway Image to Public Repo"
22

33
on:
4-
push:
5-
tags:
6-
- '*'
74
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Git tag to build. Also used as the docker image tag.'
8+
required: true
9+
type: string
810

911
env:
1012
DOCKER_IMAGE_URL: ${{ vars.REPO_DOCKER_IMAGE_URL }}
@@ -20,10 +22,7 @@ jobs:
2022
with:
2123
fetch-depth: 0
2224
fetch-tags: true
23-
24-
- name: Set Gateway Version
25-
id: set_version
26-
run: echo "GATEWAY_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo 'unknown')" >> $GITHUB_OUTPUT
25+
ref: ${{ inputs.tag }}
2726

2827
- name: Google auth
2928
id: auth
@@ -41,5 +40,5 @@ jobs:
4140
- name: Docker Auth
4241
run: |-
4342
gcloud auth configure-docker ${{ vars.GAR_LOCATION }}-docker.pkg.dev
44-
docker build --build-arg VERSION="${{ steps.set_version.outputs.GATEWAY_VERSION }}" --build-arg ARCH=amd64 -t ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }} --file Dockerfile .
45-
docker push ${{ env.DOCKER_IMAGE_URL }}:${{ steps.set_version.outputs.GATEWAY_VERSION }}
43+
docker build --build-arg VERSION="${{ inputs.tag }}" --build-arg ARCH=amd64 -t ${{ env.DOCKER_IMAGE_URL }}:${{ inputs.tag }} --file Dockerfile .
44+
docker push ${{ env.DOCKER_IMAGE_URL }}:${{ inputs.tag }}

api/api.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,11 @@ func (b *BlockChainAPI) EstimateGas(
723723
return handleError[hexutil.Uint64](err, b.logger, b.collector)
724724
}
725725

726+
blockOverridesArgs, err := json.Marshal(blockOverrides)
727+
if err != nil {
728+
return handleError[hexutil.Uint64](err, b.logger, b.collector)
729+
}
730+
726731
txArgs, err := json.Marshal(args)
727732
if err != nil {
728733
return handleError[hexutil.Uint64](err, b.logger, b.collector)
@@ -733,6 +738,7 @@ func (b *BlockChainAPI) EstimateGas(
733738
RawJSON("args", txArgs).
734739
Str("blockTag", fmt.Sprintf("%v", blockNumberOrHash)).
735740
RawJSON("stateOverrides", stateOverridesArgs).
741+
RawJSON("blockOverrides", blockOverridesArgs).
736742
Logger()
737743

738744
if err := b.rateLimiter.Apply(ctx, EthEstimateGas); err != nil {

api/debug.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func (d *DebugAPI) TraceCall(
181181

182182
if config.BlockOverrides != nil {
183183
blocksProvider = blocksProvider.WithBlockOverrides(&ethTypes.BlockOverrides{
184-
Number: config.BlockOverrides.Number,
185-
Time: config.BlockOverrides.Time,
186-
Coinbase: config.BlockOverrides.FeeRecipient,
187-
Random: config.BlockOverrides.PrevRandao,
184+
Number: config.BlockOverrides.Number,
185+
Time: config.BlockOverrides.Time,
186+
FeeRecipient: config.BlockOverrides.FeeRecipient,
187+
PrevRandao: config.BlockOverrides.PrevRandao,
188188
})
189189
}
190190
viewProvider := query.NewViewProvider(

cmd/run/cmd.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,18 @@ func parseConfigFromFlags() error {
170170
case "flow-testnet":
171171
cfg.FlowNetworkID = flowGo.Testnet
172172
cfg.EVMNetworkID = types.FlowEVMTestNetChainID
173-
cfg.InitCadenceHeight = config.LiveNetworkInitCadenceHeight
173+
cfg.InitCadenceHeight = config.TestnetInitCadenceHeight
174174
case "flow-mainnet":
175175
cfg.FlowNetworkID = flowGo.Mainnet
176176
cfg.EVMNetworkID = types.FlowEVMMainNetChainID
177-
cfg.InitCadenceHeight = config.LiveNetworkInitCadenceHeight
177+
cfg.InitCadenceHeight = config.MainnetInitCadenceHeight
178178
default:
179179
return fmt.Errorf(
180180
"flow network ID: %s not supported, valid values are ('flow-emulator', 'flow-previewnet', 'flow-testnet', 'flow-mainnet')",
181181
flowNetwork,
182182
)
183183
}
184184

185-
// if a specific value was provided use it
186-
if initHeight != 0 {
187-
cfg.InitCadenceHeight = initHeight
188-
}
189-
190185
// configure logging
191186
level, err := zerolog.ParseLevel(logLevel)
192187
if err != nil {
@@ -304,4 +299,9 @@ func init() {
304299
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.")
305300
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.")
306301
Cmd.Flags().DurationVar(&cfg.EOAActivityCacheTTL, "eoa-activity-cache-ttl", time.Second*10, "Time interval used to track EOA activity. Tx send more frequently than this interval will be batched. Useful only when batch transaction submission is enabled.")
302+
303+
err := Cmd.Flags().MarkDeprecated("init-cadence-height", "This flag is no longer necessary and will be removed in future version. The initial Cadence height is known for testnet/mainnet and this was only required for fresh deployments of EVM Gateway. Once the DB has been initialized, the latest index Cadence height will be used upon start-up.")
304+
if err != nil {
305+
panic(err)
306+
}
307307
}

config/config.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,24 @@ import (
1414
"github.com/rs/zerolog"
1515
)
1616

17-
// Default InitCadenceHeight for initializing the database on a local emulator.
18-
// TODO: temporary fix until https://github.com/onflow/flow-go/issues/5481 is
19-
// fixed upstream and released.
20-
const EmulatorInitCadenceHeight = uint64(0)
17+
const (
18+
// Default InitCadenceHeight for initializing the database on a local emulator.
19+
// TODO: temporary fix until https://github.com/onflow/flow-go/issues/5481 is
20+
// fixed upstream and released.
21+
EmulatorInitCadenceHeight = uint64(0)
22+
23+
// Default InitCadenceHeight for initializing the database on a live network.
24+
// We don't use 0 as it has a special meaning to represent latest block in the AN API context.
25+
LiveNetworkInitCadenceHeight = uint64(1)
2126

22-
// Default InitCadenceHeight for initializing the database on a live network.
23-
// We don't use 0 as it has a special meaning to represent latest block in the AN API context.
24-
const LiveNetworkInitCadenceHeight = uint64(1)
27+
// Testnet height at which the `EVM` system contract was first deployed.
28+
// This is the first height at which the EVM state starts.
29+
TestnetInitCadenceHeight = uint64(211176670)
30+
31+
// Mainnet height at which the `EVM` system contract was first deployed.
32+
// This is the first height at which the EVM state starts.
33+
MainnetInitCadenceHeight = uint64(85981134)
34+
)
2535

2636
type TxStateValidation string
2737

eth/types/types.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -433,29 +433,32 @@ type SignTransactionResult struct {
433433
// of a message call.
434434
// Note, state and stateDiff can't be specified at the same time. If state is
435435
// set, message execution will only use the data in the given state. Otherwise
436-
// if statDiff is set, all diff will be applied first and then execute the call
436+
// if stateDiff is set, all diff will be applied first and then execute the call
437437
// message.
438438
type OverrideAccount struct {
439-
Nonce *hexutil.Uint64 `json:"nonce"`
440-
Code *hexutil.Bytes `json:"code"`
441-
Balance **hexutil.Big `json:"balance"`
442-
State *map[common.Hash]common.Hash `json:"state"`
443-
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
439+
Nonce *hexutil.Uint64 `json:"nonce"`
440+
Code *hexutil.Bytes `json:"code"`
441+
Balance *hexutil.Big `json:"balance"`
442+
State map[common.Hash]common.Hash `json:"state"`
443+
StateDiff map[common.Hash]common.Hash `json:"stateDiff"`
444+
MovePrecompileTo *common.Address `json:"movePrecompileToAddress"`
444445
}
445446

446447
// StateOverride is the collection of overridden accounts.
447448
type StateOverride map[common.Address]OverrideAccount
448449

449450
// BlockOverrides is a set of header fields to override.
450451
type BlockOverrides struct {
451-
Number *hexutil.Big
452-
Difficulty *hexutil.Big
453-
Time *hexutil.Uint64
454-
GasLimit *hexutil.Uint64
455-
Coinbase *common.Address
456-
Random *common.Hash
457-
BaseFee *hexutil.Big
458-
BlobBaseFee *hexutil.Big
452+
Number *hexutil.Big
453+
Difficulty *hexutil.Big // No-op if we're simulating post-merge calls.
454+
Time *hexutil.Uint64
455+
GasLimit *hexutil.Uint64
456+
FeeRecipient *common.Address
457+
PrevRandao *common.Hash
458+
BaseFeePerGas *hexutil.Big
459+
BlobBaseFee *hexutil.Big
460+
BeaconRoot *common.Hash
461+
Withdrawals *types.Withdrawals
459462
}
460463

461464
type Block struct {

services/requester/overridable_blocks_provider.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ func (bs *blockSnapshot) BlockContext() (evmTypes.BlockContext, error) {
5454
blockContext.BlockTimestamp = uint64(*bs.blockOverrides.Time)
5555
}
5656

57-
if bs.blockOverrides.Random != nil {
58-
blockContext.Random = *bs.blockOverrides.Random
57+
if bs.blockOverrides.PrevRandao != nil {
58+
blockContext.Random = *bs.blockOverrides.PrevRandao
5959
}
6060

61-
if bs.blockOverrides.Coinbase != nil {
62-
blockContext.GasFeeCollector = evmTypes.NewAddress(*bs.blockOverrides.Coinbase)
61+
if bs.blockOverrides.FeeRecipient != nil {
62+
blockContext.GasFeeCollector = evmTypes.NewAddress(*bs.blockOverrides.FeeRecipient)
6363
}
6464

6565
return blockContext, nil

services/requester/requester.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,18 +538,18 @@ func (e *EVM) dryRunTx(
538538
}
539539
// Override account balance.
540540
if account.Balance != nil {
541-
opts = append(opts, query.WithStateOverrideBalance(addr, (*big.Int)(*account.Balance)))
541+
opts = append(opts, query.WithStateOverrideBalance(addr, (*big.Int)(account.Balance)))
542542
}
543543
if account.State != nil && account.StateDiff != nil {
544544
return nil, fmt.Errorf("account %s has both 'state' and 'stateDiff'", addr.Hex())
545545
}
546546
// Replace entire state if caller requires.
547547
if account.State != nil {
548-
opts = append(opts, query.WithStateOverrideState(addr, *account.State))
548+
opts = append(opts, query.WithStateOverrideState(addr, account.State))
549549
}
550550
// Apply state diff into specified accounts.
551551
if account.StateDiff != nil {
552-
opts = append(opts, query.WithStateOverrideStateDiff(addr, *account.StateDiff))
552+
opts = append(opts, query.WithStateOverrideStateDiff(addr, account.StateDiff))
553553
}
554554
}
555555
}

tests/e2e_web3js_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func TestWeb3_E2E(t *testing.T) {
7878
runWeb3Test(t, "eth_deploy_contract_and_interact_test")
7979
})
8080

81+
t.Run("apply state overrides", func(t *testing.T) {
82+
runWeb3Test(t, "eth_state_overrides_test")
83+
})
84+
8185
t.Run("test retrieval of contract storage slots", func(t *testing.T) {
8286
runWeb3Test(t, "eth_get_storage_at_test")
8387
})

tests/fixtures/storage.byte

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)