Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/use-new-codecv4-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo authored Oct 4, 2024
2 parents 096691e + 2ed7456 commit 8f4fed8
Show file tree
Hide file tree
Showing 17 changed files with 217 additions and 64 deletions.
2 changes: 0 additions & 2 deletions Dockerfile.mockccc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ FROM scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 as builder
ADD . /go-ethereum
RUN cd /go-ethereum && env GO111MODULE=on go run build/ci.go install ./cmd/geth

RUN cd /go-ethereum && env GO111MODULE=on go run build/ci.go install ./cmd/geth

# Pull Geth into a second stage deploy alpine container
FROM ubuntu:20.04

Expand Down
8 changes: 4 additions & 4 deletions consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF
return big.NewInt(10000000) // 0.01 Gwei
}
l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei
provingFee := big.NewInt(33700000) // 0.0337 Gwei
provingFee := big.NewInt(38200000) // 0.0382 Gwei

// L1_base_fee * 0.0034
// L1_base_fee * 0.00017
verificationFee := parentL1BaseFee
verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(34))
verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000))
verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(17))
verificationFee = new(big.Int).Div(verificationFee, big.NewInt(100000))

baseFee := big.NewInt(0)
baseFee.Add(baseFee, l2SequencerFee)
Expand Down
14 changes: 7 additions & 7 deletions consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ func TestCalcBaseFee(t *testing.T) {
parentL1BaseFee int64
expectedL2BaseFee int64
}{
{0, 34700000},
{1000000000, 38100000},
{2000000000, 41500000},
{100000000000, 374700000},
{111111111111, 412477777},
{2164000000000, 7392300000},
{2931000000000, 10000000000}, // cap at max L2 base fee
{0, 39200000},
{1000000000, 39370000},
{2000000000, 39540000},
{100000000000, 56200000},
{111111111111, 58088888},
{2164000000000, 407080000},
{58592942000000, 10000000000}, // cap at max L2 base fee
}
for i, test := range tests {
if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{
mkDynamicCreationTx(0, 500000, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), tooBigInitCode[:]),
},
want: "could not apply tx 0 [0x8f780c3573ac61e2d7796f7b447afd0ad753623ed95bc99ef94eb083d9e0d039]: max initcode size exceeded: code size 49153 limit 49152",
want: "could not apply tx 0 [0xa31de6e26bd5ffba0ca91a2bc29fc2eaad6a6cfc5ad9ab6ffb69cac121e0125c]: max initcode size exceeded: code size 49153 limit 49152",
},
{ // ErrIntrinsicGas: Not enough gas to cover init code
txs: []*types.Transaction{
mkDynamicCreationTx(0, 54299, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), smallInitCode[:]),
},
want: "could not apply tx 0 [0xbf812bb88c3f53402b6cf5488ac89360595e524b65582b648d1f4ef197690e89]: intrinsic gas too low: have 54299, want 54300",
want: "could not apply tx 0 [0xf36b7d68cf239f956f7c36be26688a97aaa317ea5f5230d109bb30dbc8598ccb]: intrinsic gas too low: have 54299, want 54300",
},
} {
block := GenerateBadBlock(genesis, ethash.NewFaker(), tt.txs, gspec.Config)
Expand Down
4 changes: 4 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if uint64(tx.Size()) > txMaxSize {
return ErrOversizedData
}
// Reject transactions that cannot fit into a block even as a single transaction
if !pool.chainconfig.Scroll.IsValidBlockSize(tx.Size()) {
return ErrOversizedData
}
// Check whether the init code size has been exceeded.
if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
Expand Down
29 changes: 29 additions & 0 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2677,3 +2677,32 @@ func TestStatsWithMinBaseFee(t *testing.T) {
}
}
}

func TestValidateTxBlockSize(t *testing.T) {
pool, key := setupTxPoolWithConfig(params.ScrollMainnetChainConfig)
defer pool.Stop()

account := crypto.PubkeyToAddress(key.PublicKey)
testAddBalance(pool, account, big.NewInt(1000000000000000000))

validTx := pricedDataTransaction(1, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)-128)
oversizedTx := pricedDataTransaction(2, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock))

tests := []struct {
name string
tx *types.Transaction
want error
}{
{"Valid transaction", validTx, nil},
{"Oversized transaction", oversizedTx, ErrOversizedData},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := pool.validateTx(tt.tx, false)
if err != tt.want {
t.Errorf("validateTx() error = %v, want %v", err, tt.want)
}
})
}
}
47 changes: 47 additions & 0 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/scroll-tech/go-ethereum/internal/ethapi"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/rollup/ccc"
"github.com/scroll-tech/go-ethereum/rpc"
"github.com/scroll-tech/go-ethereum/trie"
)
Expand Down Expand Up @@ -253,6 +254,32 @@ func (api *PrivateAdminAPI) ImportChain(file string) (bool, error) {
return true, nil
}

// SetRollupEventSyncedL1Height sets the synced L1 height for rollup event synchronization
func (api *PrivateAdminAPI) SetRollupEventSyncedL1Height(height uint64) error {
rollupSyncService := api.eth.GetRollupSyncService()
if rollupSyncService == nil {
return errors.New("RollupSyncService is not available")
}

log.Info("Setting rollup event synced L1 height", "height", height)
rollupSyncService.ResetStartSyncHeight(height)

return nil
}

// SetL1MessageSyncedL1Height sets the synced L1 height for L1 message synchronization
func (api *PrivateAdminAPI) SetL1MessageSyncedL1Height(height uint64) error {
syncService := api.eth.GetSyncService()
if syncService == nil {
return errors.New("SyncService is not available")
}

log.Info("Setting L1 message synced L1 height", "height", height)
syncService.ResetStartSyncHeight(height)

return nil
}

// PublicDebugAPI is the collection of Ethereum full node APIs exposed
// over the public debugging endpoint.
type PublicDebugAPI struct {
Expand Down Expand Up @@ -812,3 +839,23 @@ func (api *ScrollAPI) GetSkippedTransactionHashes(ctx context.Context, from uint

return hashes, nil
}

// CalculateRowConsumptionByBlockNumber
func (api *ScrollAPI) CalculateRowConsumptionByBlockNumber(ctx context.Context, number rpc.BlockNumber) (*types.RowConsumption, error) {
block := api.eth.blockchain.GetBlockByNumber(uint64(number.Int64()))
if block == nil {
return nil, errors.New("block not found")
}

// todo: fix temp AsyncChecker leaking the internal Checker instances
var checkErr error
asyncChecker := ccc.NewAsyncChecker(api.eth.blockchain, 1, false).WithOnFailingBlock(func(b *types.Block, err error) {
log.Error("failed to calculate row consumption on demand", "number", number, "hash", b.Hash().Hex(), "err", err)
checkErr = err
})
if err := asyncChecker.Check(block); err != nil {
return nil, err
}
asyncChecker.Wait()
return rawdb.ReadBlockRowConsumption(api.eth.ChainDb(), block.Hash()), checkErr
}
4 changes: 4 additions & 0 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction)
return b.eth.txPool.AddLocal(signedTx)
}

func (b *EthAPIBackend) RemoveTx(txHash common.Hash) {
b.eth.txPool.RemoveTx(txHash, true)
}

func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
pending := b.eth.txPool.Pending(false)
var txs types.Transactions
Expand Down
12 changes: 12 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,15 @@ func (s *Ethereum) Stop() error {

return nil
}

// GetRollupSyncService returns the RollupSyncService of the Ethereum instance.
// It returns nil if the service is not initialized.
func (e *Ethereum) GetRollupSyncService() *rollup_sync_service.RollupSyncService {
return e.rollupSyncService
}

// GetSyncService returns the SyncService of the Ethereum instance.
// It returns nil if the service is not initialized.
func (e *Ethereum) GetSyncService() *sync_service.SyncService {
return e.syncService
}
5 changes: 5 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ func (s *PublicTxPoolAPI) Status() map[string]hexutil.Uint {
}
}

// RemoveTransactionByHash evicts a transaction from the pool.
func (s *PublicTxPoolAPI) RemoveTransactionByHash(ctx context.Context, hash common.Hash) {
s.b.RemoveTx(hash)
}

// Inspect retrieves the content of the transaction pool and flattens it into an
// easily inspectable list.
func (s *PublicTxPoolAPI) Inspect() map[string]map[string]map[string]string {
Expand Down
1 change: 1 addition & 0 deletions internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Backend interface {

// Transaction pool API
SendTx(ctx context.Context, signedTx *types.Transaction) error
RemoveTx(txHash common.Hash)
GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, common.Hash, uint64, uint64, error)
GetPoolTransactions() (types.Transactions, error)
GetPoolTransaction(txHash common.Hash) *types.Transaction
Expand Down
21 changes: 21 additions & 0 deletions internal/web3ext/web3ext.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ web3._extend({
name: 'stopWS',
call: 'admin_stopWS'
}),
new web3._extend.Method({
name: 'setRollupEventSyncedL1Height',
call: 'admin_setRollupEventSyncedL1Height',
params: 1
}),
new web3._extend.Method({
name: 'setL1MessageSyncedL1Height',
call: 'admin_setL1MessageSyncedL1Height',
params: 1
}),
],
properties: [
new web3._extend.Property({
Expand Down Expand Up @@ -772,6 +782,11 @@ web3._extend({
call: 'txpool_contentFrom',
params: 1,
}),
new web3._extend.Method({
name: 'removeTransactionByHash',
call: 'txpool_removeTransactionByHash',
params: 1
}),
]
});
`
Expand Down Expand Up @@ -921,6 +936,12 @@ web3._extend({
inputFormatter: [web3._extend.formatters.inputCallFormatter, web3._extend.formatters.inputBlockNumberFormatter],
outputFormatter: web3._extend.utils.toDecimal
}),
new web3._extend.Method({
name: 'calculateRowConsumptionByBlockNumber',
call: 'scroll_calculateRowConsumptionByBlockNumber',
params: 1,
inputFormatter: [web3._extend.formatters.inputBlockNumberFormatter]
}),
],
properties:
[
Expand Down
Loading

0 comments on commit 8f4fed8

Please sign in to comment.