celo-org / celo-blockchain

Official repository for the golang Celo Blockchain
https://celo.org
GNU Lesser General Public License v3.0
554 stars 199 forks source link

Fix genesis block gingerbread fields #2245

Closed piersy closed 7 months ago

piersy commented 7 months ago

Description

This PR fixes the way the the gasLimit and gasPriceMinimum are retrieved from state such that for all non genesis blocks the value returned is the value present in the state of the parent block, and for the genesis block the value returned is the value present in the state of the genesis block (because the genesis has no parent). Prior to this fix requesting the gasLimit or gasPrice minimum for the genesis block would result in an error because we would try to get the state for the genesis block's parent which of course did not exist.

It also removes a restriction in the mycelo genesis package (used by e2e tests) that prevented us from setting the gingerbread activation block to zero. This restriction was in place because originally it was not possible to set the baseFeeOpCodeActivationBlock (AKA the gingerbread block) to zero in the GasPriceMinimum contract but the contract was later updated to allow this.

It also updates all e2e tests that were setting the gingerbread block to 1 to now use 0.

These fixes fix a number of flakily failing eth compatibility and gingerbread tests, that would fail if run on the genesis block.

 TestSendCelo
 TestTraceSendCeloViaGoldToken
 TestCallTraceTransactionNativeTransfer
 TestPrestateTransactionNativeTransfer
 TestEpochBlockMarshaling
 TestStartStopValidators
 TestBlockTracingConcurrentMapAccess
 TestBlockTracingSequentialAccess
 TestRPCDynamicTxGasPriceWithBigFeeCap
 TestRPCDynamicTxGasPriceWithState
 TestRPCDynamicTxGasPriceWithoutState
 TestEthersJSCompatibility
 TestEthersJSCompatibilityDisableAfterGingerbread
 TestTransferCELO
 TestTransferERC20

Tested

Two end to end tests have been added to verify the new behaviour

Backwards compatibility

This is non backwards compatible, since it is changing the gasLimit and baseFee values that people will see on the genesis block when running in eth compatibility mode. They will now see the values defined in the genesis state rather than zero.

github-actions[bot] commented 7 months ago

Coverage from tests in ./e2e_test/... for ./consensus/istanbul/... at commit c4e31a00a52418af8abe3237af41a6364992bc11

coverage: 50.7% of statements across all listed packages
coverage:  63.2% of statements in consensus/istanbul
coverage:  42.7% of statements in consensus/istanbul/announce
coverage:  55.7% of statements in consensus/istanbul/backend
coverage:   0.0% of statements in consensus/istanbul/backend/backendtest
coverage:  24.3% of statements in consensus/istanbul/backend/internal/replica
coverage:  65.0% of statements in consensus/istanbul/core
coverage:  50.0% of statements in consensus/istanbul/db
coverage:   0.0% of statements in consensus/istanbul/proxy
coverage:  64.2% of statements in consensus/istanbul/uptime
coverage:  51.8% of statements in consensus/istanbul/validator
coverage:  79.2% of statements in consensus/istanbul/validator/random
github-actions[bot] commented 7 months ago

5883 passed, 1 failed, 45 skipped

Test failures:
  TestPriorityClient: geth

    les_test.go:121: Initializing geth: [--networkid=42 init ./testdata/clique.json] 
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.678] Maximum peer count                       ETH=175 LES=0 total=175
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.680] Set global gas inflation rate            rate=1.300
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.680] Set global gas cap                       cap=25,000,000
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.680] Allocated cache and file handles         database=/tmp/geth-test1616202212/celo/chaindata cache=16.00MiB handles=16
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.735] Writing custom genesis block 
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.735] Persisted trie from memory database      nodes=4 size=566.00B time="60.908µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=-82.00B
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.736] Successfully wrote genesis state         database=chaindata                               hash=9195f2..122dcd
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.736] Allocated cache and file handles         database=/tmp/geth-test1616202212/celo/lightchaindata cache=16.00MiB handles=16
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.765] Writing custom genesis block 
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.765] Persisted trie from memory database      nodes=4 size=566.00B time="31.665µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=-82.00B
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.766] Successfully wrote genesis state         database=lightchaindata                          hash=9195f2..122dcd
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.766] Allocated cache and file handles         database=/tmp/geth-test1616202212/celo/lightestchaindata cache=16.00MiB handles=16
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.778] Writing custom genesis block 
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.778] Persisted trie from memory database      nodes=4 size=566.00B time="41.035µs" gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=-82.00B
    test_cmd.go:262: (stderr:31) INFO [02-01|17:29:46.779] Successfully wrote genesis state         database=lightestchaindata                       hash=9195f2..122dcd
    les_test.go:130: Importing keys to geth
    test_cmd.go:262: (stderr:32) INFO [02-01|17:29:46.824] Maximum peer count                       ETH=175 LES=0 total=175
    test_cmd.go:262: (stderr:32) INFO [02-01|17:29:46.826] Set global gas inflation rate            rate=1.300
    test_cmd.go:262: (stderr:32) INFO [02-01|17:29:46.826] Set global gas cap                       cap=25,000,000
    les_test.go:99: Starting lightserver with rpc: [--networkid=42 --port=0 --ipcpath geth-1.ipc --allow-insecure-unlock --datadir /tmp/geth-test1616202212 --password ./testdata/password.txt --unlock 0x02f0d131f1f97aef08aec6e3291b957d9efe7105 --mine --miner.validator 0x02f0d131f1f97aef08aec6e3291b957d9efe7105 --tx-fee-recipient 0x02f0d131f1f97aef08aec6e3291b957d9efe7105 --light.serve=100 --light.maxpeers=1 --nodiscover --nat=extip:127.0.0.1 --verbosity=4]
    test_cmd.go:262: (stderr:33) INFO [02-01|17:29:47.067] Maximum peer count                       ETH=175 LES=1 total=176
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:47.069] FS scan times                            list="217.816µs" set="3.202µs" diff="2.593µs"
    test_cmd.go:262: (stderr:33) WARN [02-01|17:29:47.069] LES server cannot serve old transaction status and cannot connect below les/4 protocol version if transaction lookup index is limited 
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:47.069] Sanitizing Go's GC trigger               percent=100
    test_cmd.go:262: (stderr:33) INFO [02-01|17:29:47.069] Set global gas inflation rate            rate=1.300
    test_cmd.go:262: (stderr:33) INFO [02-01|17:29:47.069] Set global gas cap                       cap=25,000,000
    test_cmd.go:262: (stderr:33) INFO [02-01|17:29:47.069] Allocated trie memory caches             clean=154.00MiB dirty=256.00MiB
    test_cmd.go:262: (stderr:33) INFO [02-01|17:29:47.070] Allocated cache and file handles         database=/tmp/geth-test1616202212/celo/chaindata cache=512.00MiB handles=524,288
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:50.406] Chain freezer table opened               database=/tmp/geth-test1616202212/celo/chaindata/ancient table=diffs items=0 size=0.00B
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:50.778] Chain freezer table opened               database=/tmp/geth-test1616202212/celo/chaindata/ancient table=headers items=0 size=0.00B
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:51.428] Chain freezer table opened               database=/tmp/geth-test1616202212/celo/chaindata/ancient table=hashes  items=0 size=0.00B
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:51.516] Chain freezer table opened               database=/tmp/geth-test1616202212/celo/chaindata/ancient table=bodies  items=0 size=0.00B
    test_cmd.go:262: (stderr:33) DEBUG[02-01|17:29:51.878] Chain freezer table opened               database=/tmp/geth-test1616202212/celo/chaindata/ancient table=receipts items=0 size=0.00B
    test_cmd.go:262: (stderr:33) INFO [02-01|17:29:51.879] Opened ancient database                  database=/tmp/geth-test1616202212/celo/chaindata/ancient readonly=false
    les_test.go:115: lightserver rpc connect to /tmp/geth-test1616202212/geth-1.ipc: dial unix /tmp/geth-test1616202212/geth-1.ipc: connect: no such file or directory
This test report was produced by the test-summary action.  Made with ❤️ in Cambridge.
codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (69dbdae) 55.10% compared to head (7ae8a60) 48.87%.

:exclamation: Current head 7ae8a60 differs from pull request most recent head f65c09c. Consider uploading reports for the commit f65c09c to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2245 +/- ## ========================================== - Coverage 55.10% 48.87% -6.24% ========================================== Files 683 206 -477 Lines 114538 27316 -87222 ========================================== - Hits 63121 13350 -49771 + Misses 47528 13247 -34281 + Partials 3889 719 -3170 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.