Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]Morphism geth implementation #3

Merged
merged 103 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
de64cb2
L2 consensus api
FletcherMan Apr 12, 2023
2881444
scroll new version adjustment
FletcherMan Apr 20, 2023
f32afd5
Introduce L1Message type transaction
FletcherMan Apr 26, 2023
6cb5dfe
add BLS Data
FletcherMan May 4, 2023
bfb092d
add docker-compose and modify entrypoint for dockerfile
MarvelFisher May 6, 2023
7da27f6
Merge remote-tracking branch 'upstream/develop' into fletcher/l2-geth
FletcherMan May 8, 2023
27a3830
Improve oversized block handling (#315)
Thegaram May 8, 2023
b0b0bf1
Archimedes hard fork: Disable sha2, ripemd, blake2f precompiles (#280)
maxwolff May 9, 2023
b1e5eea
add isShanghai rule based on block number (#319)
NazariiDenha May 10, 2023
29b23f4
core: implement EIP-3651, warm coinbase (#317)
NazariiDenha May 12, 2023
e1fb195
chore(github): Add PR template to ask for rationale and version updat…
OrestTa May 15, 2023
d3affee
cherry-pick commits from ethereum for the further snapshot sync using…
karalabe Nov 26, 2021
d49ea7d
writeBlockWithState with head insertion directly
FletcherMan May 18, 2023
c5da652
core/vm: implement EIP-3860: Limit and meter initcode (#23847) (#318)
NazariiDenha May 18, 2023
b8d22a1
Add Archimedes hard fork block number for Scroll Alpha (#331)
Thegaram May 18, 2023
910d4f1
feat(trace): add storage proof about l1fee (baseFee, overhead, scalar…
noel2004 May 18, 2023
e5a6851
Merge branch 'scroll/v3.2.0' into morph_v1
FletcherMan May 19, 2023
8edec7f
Merge pull request #1 from morphism-labs/morph-scroll-v3.2.0
FletcherMan May 19, 2023
1094569
feat: enable eip and update check (#335)
NazariiDenha May 19, 2023
149419c
fix(trace): deletion proof missed path terminated by empty node (#330)
noel2004 May 22, 2023
a89ab83
fix(API): use `hexutil.Big` for `l1Fee` in `GetTransactionReceipt` (#…
mask-pp May 22, 2023
2f70857
refactor(config): moved fee vault addr to rollup config (#341)
rrzhang139 May 22, 2023
0c182f1
feat(abigen): add `--contract` flag to specify a given contract (#334)
mask-pp May 22, 2023
69cf63f
fix txs p2p && testnet scripts
FletcherMan May 23, 2023
fedb314
Merge scroll tag v3.2.4 into morphism (#9)
FletcherMan May 23, 2023
9f981c5
build(github): update github action yaml (#347)
0xmountaintop May 24, 2023
374b784
optimize block validation
FletcherMan May 24, 2023
fb570dc
ci(github): update pull request template (#349)
0xmountaintop May 24, 2023
334892a
Return error for disabled precompile calls (#337)
Thegaram May 24, 2023
060815e
feat: delay Archimedes on Alpha by a week (#342)
Thegaram May 24, 2023
31b754e
Fix transaction DA cost under-estimation (#332)
Thegaram May 24, 2023
ad43d0e
feat(block_validator): check payload size during block validation (#322)
rrzhang139 May 24, 2023
74725fb
test(zkTrie): add deletion test in account update unit test (#344)
colinlyguo May 25, 2023
302c315
Merge commits under tag of scroll-v3.3.0 from scroll-tech (#10)
FletcherMan May 25, 2023
9b943f3
fix: add missing term when merging two deletion proofs (#353)
noel2004 Jun 1, 2023
667cd5e
update docker image name
Jun 5, 2023
1f167bd
fix(ethclient): support WithdrawalsHash in Scroll Go SDK (#354)
rrzhang139 Jun 5, 2023
35e4bdc
update docker-compose
MarvelFisher Jun 6, 2023
4867699
fix(tracing): fix ZktrieTracer race condition (#356)
noel2004 Jun 7, 2023
983d630
feat: Sync and relay L1 messages (#350)
Thegaram Jun 7, 2023
b120a55
enable empty block
FletcherMan Jun 8, 2023
5721f01
add feeVaultAddress into default genesis
FletcherMan Jun 8, 2023
7aaaf83
update entrypoint and docker-compose conf for devops
MarvelFisher Jun 8, 2023
8ccf1ea
update entrypoint and docker-compose conf for devops (#12)
MarvelFisher Jun 8, 2023
37de1f4
add hash
FletcherMan Jun 9, 2023
1c4a88f
fix
FletcherMan Jun 9, 2023
4e0daeb
fix(trace): change l1Fee type from uint64 to *big.Int (#360)
Thegaram Jun 9, 2023
5067662
Integrate with the commits under tag scroll v4.1.0
FletcherMan Jun 12, 2023
f055f50
feat: update l1fee calculation (#351)
0xmountaintop Jun 13, 2023
9e9747e
Merge branch 'morph/v0.0.1' of github.com:morphism-labs/go-ethereum i…
MarvelFisher Jun 13, 2023
a3f03d7
update env for docker compose
MarvelFisher Jun 13, 2023
76dfeb9
update docker compose
MarvelFisher Jun 13, 2023
b5e8d12
feat: return keccak(chainId || height) for BLOCKHASH opcode (#359)
rrzhang139 Jun 14, 2023
db4946c
execute safe block
FletcherMan Jun 16, 2023
a4a63e7
add newSafeL2Block to api client
FletcherMan Jun 16, 2023
43be9a6
feat(abigen): Add flag let be able to add user tmpl file. (#362)
mask-pp Jun 19, 2023
b14a402
fix: improve L1Message RPC encoding (#368)
Thegaram Jun 19, 2023
02b4ad4
make baseFee unnecessary
FletcherMan Jun 25, 2023
1d91b84
merge commits under scroll tag v4.2.2
FletcherMan Jun 26, 2023
1201e3f
Merge pull request #16 from morphism-labs/morph-scroll-v4.2.2
FletcherMan Jun 26, 2023
9a7bdc2
fix block rlp encode issue
FletcherMan Jun 27, 2023
749014f
add testnet geth config file (#17)
MarvelFisher Jun 27, 2023
8590393
Morph testnet deploy v0.0.1 (#18)
MarvelFisher Jun 27, 2023
0e68e48
count fix
FletcherMan Jun 28, 2023
5abc15d
feat: update contract ABI QueueIndex type to uint64 (#371)
Thegaram Jun 28, 2023
e09346e
feat(core/vm): revert modexp precompiled contract if input is not u25…
NazariiDenha Jun 28, 2023
8c141eb
feat(evm): limit ecPairing precompile to use up to 4 inputs (#373)
Thegaram Jun 29, 2023
ee7b78d
change the predeploy contract address
FletcherMan Jun 30, 2023
38a6a1e
fix: include L1MessageTx fields in transaction RPC result (#375)
Thegaram Jun 30, 2023
d99c46c
Update entrypoint.sh (#19)
MarvelFisher Jul 3, 2023
e554e93
fix test compile error
FletcherMan Jul 3, 2023
3cf5ba8
feat(trace): add per_tx_storage_trace (#372)
0xmountaintop Jul 4, 2023
b9d37e7
add new func
FletcherMan Jul 5, 2023
8c5bf30
fix(trace): fix `statesAffected` in `traceLastNAddressAccount` (#367)
0xmountaintop Jul 7, 2023
2dcc60a
fix(trace): fix storage proof of l1gas price oracle (#376)
noel2004 Jul 7, 2023
7555d08
add withdrawTrieRoot
FletcherMan Jul 10, 2023
5eac3a7
feat(core/vm): modexp precompiled support also less than 32-bytes inp…
NazariiDenha Jul 10, 2023
3943547
feat(rawdb&rpc): add block row consumption rpc (#388)
NazariiDenha Jul 11, 2023
c8ae2f9
change withdrawTrieRootSlot to 45
FletcherMan Jul 13, 2023
2e8990d
add logs for debuging
FletcherMan Jul 11, 2023
0567d64
more logs
FletcherMan Jul 14, 2023
e481942
more logs
FletcherMan Jul 14, 2023
fe3f869
separat entrypoint for testnet (#20)
MarvelFisher Jul 17, 2023
09344b9
fix estimateGas issue. similar to ethereum PR:24363
FletcherMan Jul 18, 2023
a59522f
fix the KnownBlock issue
FletcherMan Jul 19, 2023
a677ee3
fix(ethapi): change scroll_getBlockByHash ethapi behaviour (#398)
NazariiDenha Jul 19, 2023
d31c9ae
fix newL2SafeBlock
FletcherMan Jul 21, 2023
935037f
make baseFeePerGas not Must
FletcherMan Jul 21, 2023
84cdc3d
merge commits under tag of scroll-v4.2.11
FletcherMan Jul 24, 2023
88e3871
Merge pull request #21 from morphism-labs/morph-scroll-v4.2.11
FletcherMan Jul 24, 2023
52c72a4
remove parentHash from safeL2Data
FletcherMan Jul 26, 2023
f361cd6
update run testnet shell (#22)
MarvelFisher Jul 27, 2023
9ea6be2
fix compile error testcase
FletcherMan Aug 1, 2023
6751a55
update run testnet shell (#23)
MarvelFisher Aug 2, 2023
5bf9755
improve
FletcherMan Aug 2, 2023
f1c0e46
Feature/testnet runner (#24)
MarvelFisher Aug 2, 2023
663db69
Feature/testnet runner (#25)
MarvelFisher Aug 2, 2023
1cd6610
blockSize gets length of txHash involved
FletcherMan Aug 4, 2023
08f2948
add script to run testnet sentry geth
Aug 11, 2023
f136a83
update l2node geth command with --nodiscover (#26)
MarvelFisher Aug 11, 2023
8017b7e
fix incompatible block hash (#27)
FletcherMan Aug 15, 2023
bd4a942
Feature/run testnet update (#28)
MarvelFisher Aug 22, 2023
f0d9f0f
Feature/run testnet update (#29)
MarvelFisher Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: Sync and relay L1 messages (#350)
* add l1 config in genesis config (#249)

* add l1 config in genesis config

* fix lint

* Update params/config.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

---------

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* extend node configuration (#251)

* extend node configuration

* use block number instead of hash

* accept safe, finalized and numbers for L1Confirmations

* fix typos

---------

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>

* Fix/improve node config parsing (#260)

* raise error on failed parsing

* default value

* add l1-message-type, transaction methods (#252)

* add l1-message-type, transaction methods

* goimports

* Update core/types/transaction.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* txpool l1 check, pointer change, marhsal test

* draft: start implementing l1message gas behavior

* draft: start implementing l1message gas behavior

* change to gas usage

* error comment typo

Co-authored-by: Haichen Shen <shenhaichen@gmail.com>

* goimports

* update nonce, add hash test (fails), marshal test

* goimports

* target addr cant be nil

* change call msg

* comment out test

* lint

---------

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>
Co-authored-by: Haichen Shen <shenhaichen@gmail.com>

* Add L1 message database (#255)

* add l1-message-type, transaction methods

* goimports

* Update core/types/transaction.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* add L1 message store to rawdb

* remove comments

* rename to l1_message

* rename variables and add comments

* write l1 msgs in a batch

* add more comments

* update tests

* allow batched and non-batched writes

* rename to accessors_l1_message

* handle error

* add range check

* fix tests

* update comments

* nit

* support blocks with 0 l1 messages

---------

Co-authored-by: Max Wolff <maxcwolff@gmail.com>
Co-authored-by: Max Wolff <max@scroll.io>

* Fix L1Message Deep Copy, Complete Bridge Tx Hash test (#269)

* deep copy value field, add tx hash test

comment

* typo

* Rename nonce to queueindex, increment sender nonce on L1 message execution (#271)

* change nonce to queueindex, increment nonce on L1 message

* fix db acccessors

* Update core/types/transaction_marshalling.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

---------

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* Fix db inspect command (#276)

fix db inspect command

* Add l1 sync service (#256)

* extend node configuration

* add l1-message-type, transaction methods

* goimports

* Update core/types/transaction.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* use block number instead of hash

* accept safe, finalized and numbers for L1Confirmations

* add L1 message store to rawdb

* remove comments

* fix typos

* add L1 message sync service

* use l1 contract address and chain ID

* use L1DeploymentBlock

* add confirmation config

* move bridge client to separate file

* use uint64 block number

* fix bigint comparison

* rename constants

* add more logs

* rename to l1_message

* rename variables and add comments

* write l1 msgs in a batch

* add more comments

* update tests

* allow batched and non-batched writes

* rename to accessors_l1_message

* handle error

* check if config is provided

* improve sync service DB batched writes

* add range check

* fix tests

* update comments

* nit

* fix flush range and improve comments

* solve circular dependency

* update stress tests

* initialize l1 client for geth

* start sync service

* add more comments

* check nil correctly

* address comments

* fix merge

* fix genesis l1config deserialization

* add sync progress logs

* initial sync

* handle leveldb not found error

* use errors.Is

* address comments

* update DefaultPollInterval

---------

Co-authored-by: Nazarii Denha <dengaaa2002@gmail.com>
Co-authored-by: Max Wolff <maxcwolff@gmail.com>
Co-authored-by: Max Wolff <max@scroll.io>

* Add L1 message validation (#272)

* add L1 message validation

* add comments and better error handling

* handle leveldb not found error

* update incorrect condition for genesis block

* typo

* change inclusion index logic

* disable L1 message check for legacy tests

* set NumL1MessagesPerBlock to 0 in tests

* update default genesis config

* Add L1 msg validation tests (#303)

add L1 msg validation tests

* Update miner include l1 messages (#265)

* add l1-message-type, transaction methods

* goimports

* Update core/types/transaction.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* add L1 message store to rawdb

* add L1 message sync service

* remove comments

* use l1 contract address and chain ID

* extend node configuration

* use block number instead of hash

* accept safe, finalized and numbers for L1Confirmations

* fix typos

* use L1DeploymentBlock

* add confirmation config

* move bridge client to separate file

* use uint64 block number

* fix bigint comparison

* rename constants

* add more logs

* Fix/improve node config parsing (#260)

* raise error on failed parsing

* default value

* rename to l1_message

* rename variables and add comments

* write l1 msgs in a batch

* add more comments

* update tests

* allow batched and non-batched writes

* rename to accessors_l1_message

* handle error

* check if config is provided

* improve sync service DB batched writes

* include l1 messages in blocks: part 1

* add l1-message-type, transaction methods (#252)

* add l1-message-type, transaction methods

* goimports

* Update core/types/transaction.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* txpool l1 check, pointer change, marhsal test

* draft: start implementing l1message gas behavior

* draft: start implementing l1message gas behavior

* change to gas usage

* error comment typo

Co-authored-by: Haichen Shen <shenhaichen@gmail.com>

* goimports

* update nonce, add hash test (fails), marshal test

* goimports

* target addr cant be nil

* change call msg

* comment out test

* lint

---------

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>
Co-authored-by: Haichen Shen <shenhaichen@gmail.com>

* Add L1 message database (#255)

* add l1-message-type, transaction methods

* goimports

* Update core/types/transaction.go

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* add L1 message store to rawdb

* remove comments

* rename to l1_message

* rename variables and add comments

* write l1 msgs in a batch

* add more comments

* update tests

* allow batched and non-batched writes

* rename to accessors_l1_message

* handle error

* add range check

* fix tests

* update comments

* nit

* support blocks with 0 l1 messages

---------

Co-authored-by: Max Wolff <maxcwolff@gmail.com>
Co-authored-by: Max Wolff <max@scroll.io>

* build(docker): auto docker push when pushing git tags (#258)

* build(docker): update docker trigger tag prefix (#259)

* Fix L1Message Deep Copy, Complete Bridge Tx Hash test (#269)

* deep copy value field, add tx hash test

comment

* typo

* commitl1messages

* lint

* Revert "add L1 message sync service"

This reverts commit 5305e8a5de14766ed249e1a7d64042c7a72cf5c2.

* Revert "move bridge client to separate file"

This reverts commit 0b220bee37de93c3250545e23430db2c401a2f90.

* update branch

* use commitMessages for l1Txs

* little fix

* fix config

* fix test

* comment fixes

* fix

* fix config check

---------

Co-authored-by: Max Wolff <maxcwolff@gmail.com>
Co-authored-by: Max Wolff <max@scroll.io>
Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>

* Add ErrUnknownAncestor tests (#305)

add ErrUnknownAncestor tests

* worker test include l1 msgs (#306)

* worker test include l1 msgs

* move L1 message index update next to block insertion

---------

Co-authored-by: Péter Garamvölgyi <peter@scroll.io>

* exclude l1 messages from transaction count limit in block (#307)

* exclude l1 messages from transaction count limit in block

* fix comments

* trigger ci

* nit

---------

Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>
Co-authored-by: Péter Garamvölgyi <peter@scroll.io>

* Expose queueIndex on Transaction (#316)

expose queueIndex on Transaction

* test that l1msg doesn't count in maxTxPerBlock limit (#312)

* test that l1msg doesn't count in maxTxPerBlock limit

* fix, comment

* retrigger ci

* change order inside test

---------

Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Co-authored-by: Péter Garamvölgyi <th307q@gmail.com>

* reuse trace nonce field for queueIndex

* expose scroll APIs on the geth console

* add L1 message query APIs

* Trigger new block on new l1 messages (#343)

* trigger new block on new l1 messages

* typo

* initialize l1MsgCh

* fix worker l1msg tests (#345)

---------

Co-authored-by: Nazarii Denha <dengaaa2002@gmail.com>

* test(worker): ensure that l1 messages are included in the correct order (#346)

test that l1msgs added in correct order

* rename enqueueIndex --> queueIndex

* move QueueIndex into transaction

* improve l1 db interface

* formatting

* bump version

* print l1config

* add API to query latest included message queue index

* clean up tx limit logic

* add clarifying comments and todos to ValidateL1Messages

* improve db comments and logs

* clean up L1MessageTx type handling

* format

* format

* improve L1 message block check

* fix missing L1 event handling

* fix TestL1MessageValidationFailure

* simplify sync height resume logic

* make l1Config.l1MessageQueueAddress non-pointer

* improve command line flags

* remove todo

* use abigen tools for log filtering

* cache block L1 message count

* nit: fix variable name case

* improve logs

* flush pending writes to DB before shutdown

---------

Co-authored-by: Nazarii Denha <dengaaa2002@gmail.com>
Co-authored-by: Max Wolff <max@scroll.io>
Co-authored-by: Haichen Shen <shenhaichen@gmail.com>
Co-authored-by: Max Wolff <maxcwolff@gmail.com>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
  • Loading branch information
7 people authored Jun 7, 2023
commit 983d6302443376345cbcd66b98382ef94a30f9e7
1 change: 1 addition & 0 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ func (m callMsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callMsg) Value() *big.Int { return m.CallMsg.Value }
func (m callMsg) Data() []byte { return m.CallMsg.Data }
func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
func (m callMsg) IsL1MessageTx() bool { return false }

// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
Expand Down
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/ethtest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func setupGeth(stack *node.Node) error {
TrieDirtyCache: 16,
TrieTimeout: 60 * time.Minute,
SnapshotCache: 10,
})
}, nil)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ var (
utils.MinerNotifyFullFlag,
configFileFlag,
utils.CatalystFlag,
utils.L1EndpointFlag,
utils.L1ConfirmationsFlag,
utils.L1DeploymentBlockFlag,
}

rpcFlags = []cli.Flag{
Expand Down
73 changes: 72 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package utils

import (
"crypto/ecdsa"
"errors"
"fmt"
"io"
"io/ioutil"
Expand All @@ -41,6 +42,7 @@ import (
"github.com/scroll-tech/go-ethereum/accounts/keystore"
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/common/fdlimit"
"github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/consensus"
"github.com/scroll-tech/go-ethereum/consensus/clique"
"github.com/scroll-tech/go-ethereum/consensus/ethash"
Expand All @@ -53,6 +55,7 @@ import (
"github.com/scroll-tech/go-ethereum/eth/ethconfig"
"github.com/scroll-tech/go-ethereum/eth/gasprice"
"github.com/scroll-tech/go-ethereum/eth/tracers"
"github.com/scroll-tech/go-ethereum/ethclient"
"github.com/scroll-tech/go-ethereum/ethdb"
"github.com/scroll-tech/go-ethereum/ethstats"
"github.com/scroll-tech/go-ethereum/graphql"
Expand All @@ -70,6 +73,7 @@ import (
"github.com/scroll-tech/go-ethereum/p2p/nat"
"github.com/scroll-tech/go-ethereum/p2p/netutil"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rpc"
)

func init() {
Expand Down Expand Up @@ -794,6 +798,20 @@ var (
Name: "catalyst",
Usage: "Catalyst mode (eth2 integration testing)",
}

// L1Settings
L1EndpointFlag = cli.StringFlag{
Name: "l1.endpoint",
Usage: "Endpoint of L1 HTTP-RPC server",
}
L1ConfirmationsFlag = cli.StringFlag{
Name: "l1.confirmations",
Usage: "Number of confirmations on L1 needed for finalization, or \"safe\" or \"finalized\"",
}
L1DeploymentBlockFlag = cli.Int64Flag{
Name: "l1.sync.startblock",
Usage: "L1 block height to start syncing from. Should be set to the L1 message queue deployment block number.",
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down Expand Up @@ -1226,6 +1244,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
setNodeUserIdent(ctx, cfg)
setDataDir(ctx, cfg)
setSmartCard(ctx, cfg)
setL1(ctx, cfg)

if ctx.GlobalIsSet(ExternalSignerFlag.Name) {
cfg.ExternalSigner = ctx.GlobalString(ExternalSignerFlag.Name)
Expand All @@ -1251,6 +1270,42 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
}
}

func unmarshalBlockNumber(input string) (rpc.BlockNumber, error) {
switch input {
case "finalized":
return rpc.FinalizedBlockNumber, nil
case "safe":
return rpc.SafeBlockNumber, nil
}
blockNum, err := hexutil.DecodeUint64(input)
if err == nil && blockNum <= math.MaxInt64 {
return rpc.BlockNumber(blockNum), nil
}
blockNum, err = strconv.ParseUint(input, 10, 64)
if err == nil && blockNum <= math.MaxInt64 {
return rpc.BlockNumber(blockNum), nil
}
return 0, errors.New("incorrect value")
}

func setL1(ctx *cli.Context, cfg *node.Config) {
var err error
if ctx.GlobalIsSet(L1EndpointFlag.Name) {
cfg.L1Endpoint = ctx.GlobalString(L1EndpointFlag.Name)
}
if ctx.GlobalIsSet(L1ConfirmationsFlag.Name) {
cfg.L1Confirmations, err = unmarshalBlockNumber(ctx.GlobalString(L1ConfirmationsFlag.Name))
if err != nil {
panic(fmt.Sprintf("invalid value for flag %s: %s", L1ConfirmationsFlag.Name, ctx.GlobalString(L1ConfirmationsFlag.Name)))
}
} else {
cfg.L1Confirmations = rpc.FinalizedBlockNumber
}
if ctx.GlobalIsSet(L1DeploymentBlockFlag.Name) {
cfg.L1DeploymentBlock = ctx.GlobalUint64(L1DeploymentBlockFlag.Name)
}
}

func setSmartCard(ctx *cli.Context, cfg *node.Config) {
// Skip enabling smartcards if no path is set
path := ctx.GlobalString(SmartCardDaemonPathFlag.Name)
Expand Down Expand Up @@ -1732,7 +1787,23 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
stack.RegisterAPIs(tracers.APIs(backend.ApiBackend))
return backend.ApiBackend, nil
}
backend, err := eth.New(stack, cfg)

// initialize L1 client for sync service
// note: we need to do this here to avoid circular dependency
l1EndpointUrl := stack.Config().L1Endpoint
var l1Client *ethclient.Client

if l1EndpointUrl != "" {
var err error
l1Client, err = ethclient.Dial(l1EndpointUrl)
if err != nil {
Fatalf("Unable to connect to L1 endpoint at %v: %v", l1EndpointUrl, err)
}

log.Info("Initialized L1 client", "endpoint", l1EndpointUrl)
}

backend, err := eth.New(stack, cfg, l1Client)
if err != nil {
Fatalf("Failed to register the Ethereum service: %v", err)
}
Expand Down
15 changes: 15 additions & 0 deletions consensus/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@ var (

// ErrInvalidTxCount is returned if a block contains too many transactions.
ErrInvalidTxCount = errors.New("invalid transaction count")

// ErrMissingL1MessageData is returned if a block contains L1 messages that the
// node has not synced yet. In this case we insert the block into the future
// queue and process it again later.
ErrMissingL1MessageData = errors.New("unknown L1 message data")

// ErrInvalidL1MessageOrder is returned if a block contains L1 messages in the wrong
// order. Possible scenarios are: (1) L1 messages do not follow their QueueIndex order,
// (2) the block skipped one or more L1 messages, (3) L1 messages are not included in
// a contiguous block at the front of the block.
ErrInvalidL1MessageOrder = errors.New("invalid L1 message order")

// ErrUnknownL1Message is returned if a block contains an L1 message that does not
// match the corresponding message in the node's local database.
ErrUnknownL1Message = errors.New("unknown L1 message")
)
2 changes: 1 addition & 1 deletion console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func newTester(t *testing.T, confOverride func(*ethconfig.Config)) *tester {
if confOverride != nil {
confOverride(ethConf)
}
ethBackend, err := eth.New(stack, ethConf)
ethBackend, err := eth.New(stack, ethConf, nil)
if err != nil {
t.Fatalf("failed to register Ethereum protocol: %v", err)
}
Expand Down
70 changes: 69 additions & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"

"github.com/scroll-tech/go-ethereum/consensus"
"github.com/scroll-tech/go-ethereum/core/rawdb"
"github.com/scroll-tech/go-ethereum/core/state"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/params"
Expand Down Expand Up @@ -54,7 +55,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
return ErrKnownBlock
}
if !v.config.Scroll.IsValidTxCount(len(block.Transactions())) {
if !v.config.Scroll.IsValidL2TxCount(block.CountL2Tx()) {
return consensus.ErrInvalidTxCount
}
// Check if block payload size is smaller than the max size
Expand All @@ -78,6 +79,73 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
}
return consensus.ErrPrunedAncestor
}
return v.ValidateL1Messages(block)
}

// ValidateL1Messages validates L1 messages contained in a block.
// We check the following conditions:
// - L1 messages are in a contiguous section at the front of the block.
// - The first L1 message's QueueIndex is right after the last L1 message included in the chain.
// - L1 messages follow the QueueIndex order. No L1 message is skipped.
// - The L1 messages included in the block match the node's view of the L1 ledger.
func (v *BlockValidator) ValidateL1Messages(block *types.Block) error {
// no further processing if the block contains no L1 messages
if block.L1MessageCount() == 0 {
return nil
}

if v.config.Scroll.L1Config == nil {
// TODO: should we allow follower nodes to skip L1 message verification?
panic("Running on L1Message-enabled network but no l1Config was provided")
}

nextQueueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(v.bc.db, block.ParentHash())
if nextQueueIndex == nil {
// we'll reprocess this block at a later time
return consensus.ErrMissingL1MessageData
}
queueIndex := *nextQueueIndex

L1SectionOver := false
it := rawdb.IterateL1MessagesFrom(v.bc.db, queueIndex)

for _, tx := range block.Transactions() {
if !tx.IsL1MessageTx() {
L1SectionOver = true
continue // we do not verify L2 transactions here
}

// check that L1 messages are before L2 transactions
if L1SectionOver {
return consensus.ErrInvalidL1MessageOrder
}

// check queue index
// TODO: account for skipped messages here
if tx.AsL1MessageTx().QueueIndex != queueIndex {
return consensus.ErrInvalidL1MessageOrder
}

queueIndex += 1

if exists := it.Next(); !exists {
// we'll reprocess this block at a later time
return consensus.ErrMissingL1MessageData
}

// check that the L1 message in the block is the same that we collected from L1
msg := it.L1Message()
expectedHash := types.NewTx(&msg).Hash()

if tx.Hash() != expectedHash {
return consensus.ErrUnknownL1Message
}
}

// TODO: consider adding a rule to enforce L1Config.NumL1MessagesPerBlock.
// If there are L1 messages available, sequencer nodes should include them.
// However, this is hard to enforce as different nodes might have different views of L1.

return nil
}

Expand Down
26 changes: 24 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
return nil, ErrNoGenesis
}

// initialize L1 message index for genesis block
rawdb.WriteFirstQueueIndexNotInL2Block(db, bc.genesisBlock.Hash(), 0)

var nilBlock *types.Block
bc.currentBlock.Store(nilBlock)
bc.currentFastBlock.Store(nilBlock)
Expand Down Expand Up @@ -695,6 +698,7 @@ func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) error {
batch := bc.db.NewBatch()
rawdb.WriteTd(batch, genesis.Hash(), genesis.NumberU64(), genesis.Difficulty())
rawdb.WriteBlock(batch, genesis)
rawdb.WriteFirstQueueIndexNotInL2Block(batch, genesis.Hash(), 0)
if err := batch.Write(); err != nil {
log.Crit("Failed to write genesis block", "err", err)
}
Expand Down Expand Up @@ -1176,6 +1180,14 @@ func (bc *BlockChain) writeBlockWithoutState(block *types.Block, td *big.Int) (e
batch := bc.db.NewBatch()
rawdb.WriteTd(batch, block.Hash(), block.NumberU64(), td)
rawdb.WriteBlock(batch, block)

queueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(bc.db, block.ParentHash())
if queueIndex != nil {
// note: we can insert blocks with header-only ancestors here,
// so queueIndex might not yet be available in DB.
rawdb.WriteFirstQueueIndexNotInL2Block(batch, block.Hash(), *queueIndex+uint64(block.L1MessageCount()))
}

if err := batch.Write(); err != nil {
log.Crit("Failed to write block into disk", "err", err)
}
Expand Down Expand Up @@ -1230,6 +1242,15 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
rawdb.WriteBlock(blockBatch, block)
rawdb.WriteReceipts(blockBatch, block.Hash(), block.NumberU64(), receipts)
rawdb.WritePreimages(blockBatch, state.Preimages())

queueIndex := rawdb.ReadFirstQueueIndexNotInL2Block(bc.db, block.ParentHash())
if queueIndex == nil {
// We expect that we only insert contiguous chain segments,
// so the parent will always be inserted first.
log.Crit("Queue index in DB is nil", "parent", block.ParentHash(), "hash", block.Hash())
}
rawdb.WriteFirstQueueIndexNotInL2Block(blockBatch, block.Hash(), *queueIndex+uint64(block.L1MessageCount()))

if err := blockBatch.Write(); err != nil {
log.Crit("Failed to write block into disk", "err", err)
}
Expand Down Expand Up @@ -1500,7 +1521,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
return bc.insertSideChain(block, it)

// First block is future, shove it (and all children) to the future queue (unknown ancestor)
case errors.Is(err, consensus.ErrFutureBlock) || (errors.Is(err, consensus.ErrUnknownAncestor) && bc.futureBlocks.Contains(it.first().ParentHash())):
case errors.Is(err, consensus.ErrFutureBlock) || errors.Is(err, consensus.ErrMissingL1MessageData) || (errors.Is(err, consensus.ErrUnknownAncestor) && bc.futureBlocks.Contains(it.first().ParentHash())):
for block != nil && (it.index == 0 || errors.Is(err, consensus.ErrUnknownAncestor)) {
log.Debug("Future block, postponing import", "number", block.Number(), "hash", block.Hash())
if err := bc.addFutureBlock(block); err != nil {
Expand Down Expand Up @@ -2175,11 +2196,12 @@ Chain config: %v

Number: %v
Hash: 0x%x
ParentHash: 0x%x
%v

Error: %v
##############################
`, bc.chainConfig, block.Number(), block.Hash(), receiptString, err))
`, bc.chainConfig, block.Number(), block.Hash(), block.ParentHash(), receiptString, err))
}

// InsertHeaderChain attempts to insert the given header chain in to the local
Expand Down
Loading