Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion accounts/abi/bind/v2/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ func TestWaitDeployed(t *testing.T) {
}
}

func TestWaitDeployedCornerCases(t *testing.T) {
// TODO(Eric): need fix
//
//nolint:unused
func testWaitDeployedCornerCases(t *testing.T) {
backend := simulated.NewBackend(
types.GenesisAlloc{
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
Expand Down
23 changes: 4 additions & 19 deletions cmd/geth/accountcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
package main

import (
"errors"
"fmt"
"os"
"strings"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -346,23 +344,10 @@ func accountUpdate(ctx *cli.Context) error {
ks := backends[0].(*keystore.KeyStore)

for _, addr := range ctx.Args().Slice() {
if !common.IsHexAddress(addr) {
return errors.New("address must be specified in hexadecimal form")
}
account := accounts.Account{Address: common.HexToAddress(addr)}
newPassword := utils.GetPassPhrase("Please give a NEW password. Do not forget this password.", true)
updateFn := func(attempt int) error {
prompt := fmt.Sprintf("Please provide the OLD password for account %s | Attempt %d/%d", addr, attempt+1, 3)
password := utils.GetPassPhrase(prompt, false)
return ks.Update(account, password, newPassword)
}
// let user attempt unlock thrice.
err := updateFn(0)
for attempts := 1; attempts < 3 && errors.Is(err, keystore.ErrDecrypt); attempts++ {
err = updateFn(attempts)
}
if err != nil {
return fmt.Errorf("could not update account: %w", err)
account, oldPassword := unlockAccount(ks, addr, 0, nil)
newPassword := utils.GetPassPhraseWithList("Please give a new password. Do not forget this password.", true, 0, nil)
if err := ks.Update(account, oldPassword, newPassword); err != nil {
utils.Fatalf("Could not update the account: %v", err)
}
}
return nil
Expand Down
7 changes: 7 additions & 0 deletions cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/naoina/toml"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -192,6 +193,12 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
v := ctx.Uint64(utils.OverrideVerkle.Name)
cfg.Eth.OverrideVerkle = &v
}
if ctx.IsSet(utils.OverrideMinBlocksForBlobRequests.Name) {
params.MinBlocksForBlobRequests = ctx.Uint64(utils.OverrideMinBlocksForBlobRequests.Name)
}
if ctx.IsSet(utils.OverrideDefaultExtraReserveForBlobRequests.Name) {
params.DefaultExtraReserveForBlobRequests = ctx.Uint64(utils.OverrideDefaultExtraReserveForBlobRequests.Name)
}

// Start metrics export if enabled
utils.SetupMetrics(&cfg.Metrics)
Expand Down
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ var (
utils.SmartCardDaemonPathFlag,
utils.OverridePrague,
utils.OverrideVerkle,
utils.OverrideMinBlocksForBlobRequests,
utils.OverrideDefaultExtraReserveForBlobRequests,
utils.EnablePersonal, // deprecated
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
Expand Down Expand Up @@ -175,6 +177,7 @@ var (
utils.BeaconGenesisTimeFlag,
utils.BeaconCheckpointFlag,
utils.BeaconCheckpointFileFlag,
utils.BlobExtraReserveFlag,
}, utils.NetworkFlags, utils.DatabaseFlags)

rpcFlags = []cli.Flag{
Expand Down
29 changes: 29 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,26 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.
Value: metrics.DefaultConfig.InfluxDBOrganization,
Category: flags.MetricsCategory,
}

// Blob setting
BlobExtraReserveFlag = &cli.Uint64Flag{
Name: "blob.extra-reserve",
Usage: "Extra reserve threshold for blob, blob never expires when 0 is set, default 314496",
Value: params.DefaultExtraReserveForBlobRequests,
Category: flags.MiscCategory,
}
OverrideMinBlocksForBlobRequests = &cli.Uint64Flag{
Name: "override.minforblobrequests",
Usage: "It keeps blob data available for min blocks in local, only for testing purpose",
Value: params.MinBlocksForBlobRequests,
Category: flags.EthCategory,
}
OverrideDefaultExtraReserveForBlobRequests = &cli.Uint64Flag{
Name: "override.defaultextrareserve",
Usage: "It adds more extra time for expired blobs for some request cases, only for testing purpose",
Value: params.DefaultExtraReserveForBlobRequests,
Category: flags.EthCategory,
}
)

var (
Expand Down Expand Up @@ -2046,6 +2066,15 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
cfg.VMTraceJsonConfig = ctx.String(VMTraceJsonConfigFlag.Name)
}
}

// blob setting
if ctx.IsSet(BlobExtraReserveFlag.Name) {
extraReserve := ctx.Uint64(BlobExtraReserveFlag.Name)
if extraReserve > 0 && extraReserve < params.DefaultExtraReserveForBlobRequests {
extraReserve = params.DefaultExtraReserveForBlobRequests
}
cfg.BlobExtraReserve = extraReserve
}
}

// MakeBeaconLightConfig constructs a beacon light client config based on the
Expand Down
3 changes: 3 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type ChainHeaderReader interface {

// GetTd retrieves the total difficulty from the database by hash and number.
GetTd(hash common.Hash, number uint64) *big.Int

// ChasingHead return the best chain head of peers.
ChasingHead() *types.Header
}

// ChainReader defines a small collection of methods needed to access the local
Expand Down
8 changes: 1 addition & 7 deletions consensus/dbft/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,10 @@ func (api *API) Status(n *uint64) (*status, error) {
var (
numBlocks = api.config.DefaultStatisticsPeriod
header = api.chain.CurrentHeader()
diff = uint64(0)
optimals = 0
)
if n != nil {
if *n <= api.config.MaxStatisticsPeriod {
numBlocks = *n
} else {
numBlocks = api.config.MaxStatisticsPeriod
}
numBlocks = min(*n, api.config.MaxStatisticsPeriod)
}
var (
end = header.Number.Uint64()
Expand All @@ -156,7 +151,6 @@ func (api *API) Status(n *uint64) (*status, error) {
if h.Difficulty.Cmp(diffInTurn) == 0 {
optimals++
}
diff += h.Difficulty.Uint64()
sealer, err := api.bft.Primary(h)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions consensus/dbft/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Block struct {
header *types.Header
withdrawals []*types.Withdrawal
transactions []*types.Transaction
sidecars types.BlobSidecars
localSignatureBytes []byte

// Local data got after [dbft.Block] construction. Always non-nil in a properly
Expand Down
29 changes: 28 additions & 1 deletion consensus/dbft/dbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ type DBFT struct {
// about a new consensus payload to be sent.
broadcast func(m *dbftproto.Message) error

// blobsFeed is a feed to notify new blobs arrivals.
blobsFeed event.Feed

// requestTxs is a callback which is called to request the missing
// transactions from neighbor nodes. Requested transactions hashes are
// stored in txCbList and checked against the incoming transactions. If
Expand Down Expand Up @@ -250,6 +253,7 @@ type DBFT struct {
// mutex since every access point is controlled by eventLoop, thus, not concurrent.
sealingProposal *types.Header
sealingTransactions types.Transactions
sealingSidecars types.BlobSidecars

// sealingState, sealingBlock and sealingReceipts are Primary-only set of fields got
// after sealingProposal construction and processing. These fields are not protected
Expand Down Expand Up @@ -558,6 +562,10 @@ func (c *DBFT) processBlockCb(b dbft.Block[common.Hash]) error {
state := dbftBlock.state.Copy()
res := types.NewBlockWithHeader(dbftBlock.header).WithBody(types.Body{Transactions: dbftBlock.transactions, Uncles: nil, Withdrawals: dbftBlock.withdrawals})

if c.chain.Config().IsCancun(dbftBlock.header.Number, dbftBlock.header.Time) {
res = res.WithSidecars(dbftBlock.sidecars).WithSeal(dbftBlock.header)
}

// Firstly, notify chain about new block.
if err := c.blockQueue.PutBlock(res, dbftBlock.state, dbftBlock.receipts); err != nil {
// The block might already be added via the regular network
Expand All @@ -567,6 +575,14 @@ func (c *DBFT) processBlockCb(b dbft.Block[common.Hash]) error {
}
}

// Notify new blobs arrival.
if len(dbftBlock.sidecars) > 0 {
c.blobsFeed.Send(core.NewBlobsEvent{Blob: &types.BlockBlobs{
BlockHash: res.Hash(),
Sidecars: res.Sidecars(),
}})
}

c.postBlock(res.Header(), state)
return nil
}
Expand All @@ -591,6 +607,7 @@ func (c *DBFT) newBlockFromContextCb(ctx *dbft.Context[common.Hash]) dbft.Block[
if ctx.IsPrimary() {
res.state = c.sealingState
res.receipts = c.sealingReceipts
res.sidecars = c.sealingSidecars
}
return res
}
Expand All @@ -603,6 +620,7 @@ func (c *DBFT) newBlockFromContextCb(ctx *dbft.Context[common.Hash]) dbft.Block[
header: c.sealingBlock.Header(),
withdrawals: c.sealingBlock.Withdrawals(),
transactions: c.sealingBlock.Transactions(),
sidecars: c.sealingBlock.Sidecars(),
localSignatureBytes: nil,
state: c.sealingState,
receipts: c.sealingReceipts,
Expand Down Expand Up @@ -761,6 +779,9 @@ func (c *DBFT) newPrepareRequestCb(ts uint64, nonce uint64, txHashes []common.Ha
log.Crit("Failed to finalize and assemble proposed block",
"err", err)
}
if c.chain.Config().IsCancun(res.Header().Number, res.Header().Time) {
res = res.WithSidecars(c.sealingSidecars)
}

c.sealingProposal = res.Header()
c.sealingState = state
Expand Down Expand Up @@ -950,6 +971,7 @@ func (c *DBFT) verifyPrepareRequestCb(p dbft.ConsensusPayload[common.Hash]) erro
// sealingTransactions are not needed for proper dBFT functioning (dBFT will collect
// transactions via internal mechanism in this consensus view).
c.sealingTransactions = nil
c.sealingSidecars = nil

return nil
}
Expand Down Expand Up @@ -1026,6 +1048,9 @@ func (c *DBFT) verifyBlockCb(b dbft.Block[common.Hash]) bool {
}

ethBlock := types.NewBlockWithHeader(dbftBlock.header).WithBody(types.Body{Transactions: dbftBlock.transactions, Uncles: nil, Withdrawals: dbftBlock.withdrawals})
if c.chain.Config().IsCancun(ethBlock.Header().Number, ethBlock.Header().Time) {
ethBlock = ethBlock.WithSidecars(dbftBlock.sidecars)
}
state, receipts, _, err := c.chain.VerifyBlock(ethBlock, true)
if err != nil {
log.Warn("proposed block verification failed",
Expand Down Expand Up @@ -2346,11 +2371,13 @@ func (c *DBFT) waitForNewSealingProposal(desiredHeight uint64, updateContext boo

c.sealingProposal = lastProposal.Header()
c.sealingTransactions = lastProposal.Transactions()
c.sealingSidecars = lastProposal.Sidecars()
log.Info("Sealing proposal updated",
"number", c.sealingProposal.Number,
"sealhash", c.SealHash(c.sealingProposal),
"parent hash", c.sealingProposal.ParentHash,
"txs", len(c.sealingTransactions))
"txs", len(c.sealingTransactions),
"sidecars", len(c.sealingSidecars))

if updateContext {
// dBFT can't update its PrevHash in the middle of consensus process, thus,
Expand Down
10 changes: 10 additions & 0 deletions consensus/dbft/subscribe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dbft

import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/event"
)

func (dbft *DBFT) SubscribeBlobs(ch chan<- core.NewBlobsEvent) event.Subscription {
return dbft.blobsFeed.Subscribe(ch)
}
24 changes: 24 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const (
bodyCacheLimit = 256
blockCacheLimit = 256
receiptsCacheLimit = 32
sidecarsCacheLimit = 1024
txLookupCacheLimit = 1024
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
Expand Down Expand Up @@ -263,11 +264,13 @@ type BlockChain struct {
currentFinalBlock atomic.Pointer[types.Header] // Latest (consensus) finalized block
currentSafeBlock atomic.Pointer[types.Header] // Latest (consensus) safe block
historyPrunePoint atomic.Pointer[history.PrunePoint]
chasingHead atomic.Pointer[types.Header]

bodyCache *lru.Cache[common.Hash, *types.Body]
bodyRLPCache *lru.Cache[common.Hash, rlp.RawValue]
receiptsCache *lru.Cache[common.Hash, []*types.Receipt]
blockCache *lru.Cache[common.Hash, *types.Block]
sidecarsCache *lru.Cache[common.Hash, types.BlobSidecars]

txLookupLock sync.RWMutex
txLookupCache *lru.Cache[common.Hash, txLookup]
Expand Down Expand Up @@ -333,6 +336,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit),
receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit),
blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit),
sidecarsCache: lru.NewCache[common.Hash, types.BlobSidecars](sidecarsCacheLimit),
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks),
engine: engine,
Expand Down Expand Up @@ -360,6 +364,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc.currentSnapBlock.Store(nil)
bc.currentFinalBlock.Store(nil)
bc.currentSafeBlock.Store(nil)
bc.chasingHead.Store(nil)

// Update chain info data metrics
chainInfoGauge.Update(metrics.GaugeInfoValue{"chain_id": bc.chainConfig.ChainID.String()})
Expand Down Expand Up @@ -1010,6 +1015,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
// removed in the hc.SetHead function.
rawdb.DeleteBody(db, hash, num)
rawdb.DeleteReceipts(db, hash, num)
rawdb.DeleteBlobSidecars(db, hash, num)
}
// Todo(rjl493456442) txlookup, log index, etc
}
Expand All @@ -1035,6 +1041,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha
bc.bodyRLPCache.Purge()
bc.receiptsCache.Purge()
bc.blockCache.Purge()
bc.sidecarsCache.Purge()
bc.txLookupCache.Purge()
bc.futureBlocks.Purge()

Expand Down Expand Up @@ -1085,6 +1092,16 @@ func (bc *BlockChain) SnapSyncCommitHead(hash common.Hash) error {
return nil
}

// UpdateChasingHead update remote best chain head, used by DA check now.
func (bc *BlockChain) UpdateChasingHead(head *types.Header) {
bc.chasingHead.Store(head)
}

// ChasingHead return the best chain head of peers.
func (bc *BlockChain) ChasingHead() *types.Header {
return bc.chasingHead.Load()
}

// Reset purges the entire blockchain, restoring it to its genesis state.
func (bc *BlockChain) Reset() error {
return bc.ResetWithGenesisBlock(bc.genesisBlock)
Expand Down Expand Up @@ -1670,6 +1687,13 @@ func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types
if err := bc.writeBlockWithState(block, receipts, state); err != nil {
return NonStatTy, err
}
// if cancun is enabled, here need to write sidecars too
if bc.chainConfig.IsCancun(block.Number(), block.Time()) && block.HasBlobTxs() {
if len(block.Sidecars()) > 0 {
rawdb.WriteBlobSidecars(bc.db, block.Hash(), block.NumberU64(), block.Sidecars())
bc.sidecarsCache.Add(block.Hash(), block.Sidecars())
}
}
currentBlock := bc.CurrentBlock()

// Reorganise the chain if the parent is not the head block
Expand Down
Loading
Loading