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

chore: some comments #22

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
12 changes: 5 additions & 7 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@
"strings"
"time"

"github.com/ethereum/go-ethereum/core/txpool/bundlepool"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
"github.com/urfave/cli/v2"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/opcodeCompiler/compiler"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/txpool/bundlepool"
"github.com/ethereum/go-ethereum/core/txpool/legacypool"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -78,6 +74,8 @@
"github.com/ethereum/go-ethereum/triedb"
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"
pcsclite "github.com/gballet/go-libpcsclite"
gopsutil "github.com/shirou/gopsutil/mem"
)

// These are all the command line flags we support.
Expand All @@ -95,18 +93,18 @@
Value: flags.DirectoryString(node.DefaultDataDir()),
Category: flags.EthCategory,
}
MultiDataBaseFlag = &cli.BoolFlag{

Check failure on line 96 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "multidatabase",
Usage: "Enable a separated state and block database, it will be created within two subdirectory called state and block, " +
"Users can copy this state or block directory to another directory or disk, and then create a symbolic link to the state directory under the chaindata",
Category: flags.EthCategory,
}
RemoteDBFlag = &cli.StringFlag{

Check failure on line 102 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "remotedb",
Usage: "URL for remote database",
Category: flags.LoggingCategory,
}
DBEngineFlag = &cli.StringFlag{

Check failure on line 107 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "db.engine",
Usage: "Backing database implementation to use ('pebble' or 'leveldb')",
Value: node.DefaultConfig.DBEngine,
Expand All @@ -127,39 +125,39 @@
Usage: "Directory for the keystore (default = inside the datadir)",
Category: flags.AccountCategory,
}
USBFlag = &cli.BoolFlag{

Check failure on line 128 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "usb",
Usage: "Enable monitoring and management of USB hardware wallets",
Category: flags.AccountCategory,
}
SmartCardDaemonPathFlag = &cli.StringFlag{

Check failure on line 133 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "pcscdpath",
Usage: "Path to the smartcard daemon (pcscd) socket file",
Value: pcsclite.PCSCDSockName,
Category: flags.AccountCategory,
}
NetworkIdFlag = &cli.Uint64Flag{

Check failure on line 139 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "networkid",
Usage: "Explicitly set network id (integer)(For testnets: use --goerli, --sepolia, --holesky instead)",
Value: ethconfig.Defaults.NetworkId,
Category: flags.EthCategory,
}
MainnetFlag = &cli.BoolFlag{

Check failure on line 145 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "mainnet",
Usage: "Ethereum mainnet",
Category: flags.EthCategory,
}
GoerliFlag = &cli.BoolFlag{

Check failure on line 150 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "goerli",
Usage: "Görli network: pre-configured proof-of-authority test network",
Category: flags.EthCategory,
}
SepoliaFlag = &cli.BoolFlag{

Check failure on line 155 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "sepolia",
Usage: "Sepolia network: pre-configured proof-of-work test network",
Category: flags.EthCategory,
}
HoleskyFlag = &cli.BoolFlag{

Check failure on line 160 in cmd/utils/flags.go

View workflow job for this annotation

GitHub Actions / unit_test

undefined: cli
Name: "holesky",
Usage: "Holesky network: pre-configured proof-of-stake test network",
Category: flags.EthCategory,
Expand Down Expand Up @@ -579,12 +577,12 @@
}
MinerRecommitIntervalFlag = &cli.DurationFlag{
Name: "miner.recommit",
Usage: "Time interval to recreate the block being mined",
Usage: "Time interval to recreate the block being mined", // ??
Value: ethconfig.Defaults.Miner.Recommit,
Category: flags.MinerCategory,
}
MinerNewPayloadTimeout = &cli.DurationFlag{
Name: "miner.newpayload-timeout",
Name: "miner.newpayload-timeout", // ??
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

关注这几个参数配置

Usage: "Specify the maximum time allowance for creating a new payload",
Value: ethconfig.Defaults.Miner.NewPayloadTimeout,
Category: flags.MinerCategory,
Expand Down
38 changes: 38 additions & 0 deletions env.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/jiaqiwang/Library/Caches/go-build"
GOENV="/Users/jiaqiwang/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jiaqiwang/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jiaqiwang/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jiaqiwang/workspace/op-geth/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1p/80zcsvjx28jc9wmj7nj3sxyc0000gn/T/go-build214093898=/tmp/go-build -gno-record-gcc-switches -fno-common"
7 changes: 4 additions & 3 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
BeaconRoot: payloadAttributes.BeaconRoot,
NoTxPool: payloadAttributes.NoTxPool,
Transactions: transactions,
GasLimit: payloadAttributes.GasLimit,
GasLimit: payloadAttributes.GasLimit, // 非空
Version: payloadVersion,
}
id := args.Id()
Expand All @@ -443,7 +443,7 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
log.Error("Failed to build payload", "err", err)
return valid(nil), engine.InvalidPayloadAttributes.With(err)
}
api.localBlocks.put(id, payload)
api.localBlocks.put(id, payload) // here
forkchoiceUpdateAttributesTimer.UpdateSince(start)
log.Debug("forkchoiceUpdateAttributesTimer", "duration", common.PrettyDuration(time.Since(start)), "id", id)
return valid(&id), nil
Expand Down Expand Up @@ -609,6 +609,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
block := api.localBlocks.getBlockByHash(params.BlockHash)
if block == nil {
var err error
// attributes 到 block
block, err = engine.ExecutableDataToBlock(params, versionedHashes, beaconRoot)
if err != nil {
log.Warn("Invalid NewPayload params", "params", params, "error", err)
Expand Down Expand Up @@ -679,7 +680,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
return engine.PayloadStatusV1{Status: engine.ACCEPTED}, nil
}
log.Trace("Inserting block without sethead", "hash", block.Hash(), "number", block.Number)
if err := api.eth.BlockChain().InsertBlockWithoutSetHead(block); err != nil {
if err := api.eth.BlockChain().InsertBlockWithoutSetHead(block); err != nil { // 塞入chain
log.Warn("NewPayloadV1: inserting block failed", "error", err)

api.invalidLock.Lock()
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ require (
github.com/dgraph-io/ristretto v0.0.4-0.20210318174700-74754f61e018 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ferranbt/fastssz v0.0.0-20210905181407-59cf6761a7d5 // indirect
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZi
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
github.com/emicklei/dot v0.11.0/go.mod h1:DeV7GvQtIw4h2u73RKBkkFdvVAz0D9fzeJrgPW6gy/s=
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
21 changes: 11 additions & 10 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type BuildPayloadArgs struct {
}

// Id computes an 8-byte identifier by hashing the components of the payload arguments.
func (args *BuildPayloadArgs) Id() engine.PayloadID {
func (args *BuildPayloadArgs) Id() engine.PayloadID { // payload计算方式
// Hash
hasher := sha256.New()
hasher.Write(args.Parent[:])
Expand Down Expand Up @@ -203,6 +203,7 @@ func (payload *Payload) WaitFull() {
}

func (payload *Payload) resolve(onlyFull bool) *engine.ExecutionPayloadEnvelope {
// 终止
payload.lock.Lock()
defer payload.lock.Unlock()

Expand Down Expand Up @@ -331,9 +332,9 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {

fullParams := &generateParams{
timestamp: args.Timestamp,
forceTime: true,
forceTime: true, // 什么意思??
parentHash: args.Parent,
coinbase: args.FeeRecipient,
coinbase: args.FeeRecipient, //
random: args.Random,
withdrawals: args.Withdrawals,
beaconRoot: args.BeaconRoot,
Expand All @@ -349,7 +350,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
return nil, err
}

//check state of parent block
// check state of parent block
_, err = w.retrieveParentState(fullParams)
if err != nil && strings.Contains(err.Error(), "missing trie node") {
log.Error("missing parent state when building block, try to fix...")
Expand All @@ -362,28 +363,28 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
}

payload := newPayload(nil, args.Id())
// set shared interrupt
// set shared interrupt; 外部可以中断building
fullParams.interrupt = payload.interrupt

// Spin up a routine for updating the payload in background. This strategy
// can maximum the revenue for including transactions with highest fee.
go func() {
// Setup the timer for re-building the payload. The initial clock is kept
// for triggering process immediately.
timer := time.NewTimer(0)
timer := time.NewTimer(0) // 怎么使用??
defer timer.Stop()

start := time.Now()
// Setup the timer for terminating the payload building process as determined
// by validateParams.
endTimer := time.NewTimer(blockTime)
endTimer := time.NewTimer(blockTime) //
defer endTimer.Stop()

timeout := time.Now().Add(blockTime)

stopReason := "delivery"
defer func() {
log.Info("Stopping work on payload",
log.Info("Stopping work on payload", // 线上grep 日志 看看
"id", payload.id,
"reason", stopReason,
"elapsed", common.PrettyDuration(time.Since(start)))
Expand All @@ -404,7 +405,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
} else {
log.Error("Failed to build full payload", "id", payload.id, "err", r.err)
}
timer.Reset(w.recommit)
timer.Reset(w.recommit) // 这个是多少??
return dur
}

Expand All @@ -425,7 +426,7 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
stopReason = "near-timeout"
return
}
lastDuration = updatePayload()
lastDuration = updatePayload() // here
case <-payload.stop:
return
case <-endTimer.C:
Expand Down
20 changes: 12 additions & 8 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
worker.recommit = recommit

// Sanitize the timeout config for creating payload.
newpayloadTimeout := worker.config.NewPayloadTimeout
newpayloadTimeout := worker.config.NewPayloadTimeout // 需要看一下,650ms??
if newpayloadTimeout == 0 {
log.Warn("Sanitizing new payload timeout to default", "provided", newpayloadTimeout, "updated", DefaultConfig.NewPayloadTimeout)
newpayloadTimeout = DefaultConfig.NewPayloadTimeout
Expand Down Expand Up @@ -674,7 +674,7 @@ func (w *worker) opLoop() {
defer w.wg.Done()
for {
select {
case req := <-w.getWorkCh:
case req := <-w.getWorkCh: // here
req.result <- w.generateWork(req.params)
case <-w.exitCh:
return
Expand Down Expand Up @@ -918,6 +918,7 @@ func (w *worker) applyTransaction(env *environment, tx *types.Transaction) (*typ
return receipt, err
}

// 怎么理解??
func (w *worker) commitTransactions(env *environment, plainTxs, blobTxs *transactionsByPriceAndNonce, interrupt *atomic.Int32) error {
gasLimit := env.header.GasLimit
if env.gasPool == nil {
Expand Down Expand Up @@ -1162,12 +1163,13 @@ func (w *worker) validateParams(genParams *generateParams) (time.Duration, error
}

// Sanity check the timestamp correctness
blockTime := int64(genParams.timestamp) - int64(parent.Time)
blockTime := int64(genParams.timestamp) - int64(parent.Time) // 这里是秒级别时间戳??
if blockTime <= 0 && genParams.forceTime {
return 0, fmt.Errorf("invalid timestamp, parent %d given %d", parent.Time, genParams.timestamp)
}

// minimum payload build time of 1s
// 这里需要调整
if blockTime < 1 {
blockTime = 1
}
Expand Down Expand Up @@ -1250,12 +1252,13 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) {
// Could potentially happen if starting to mine in an odd state.
// Note genParams.coinbase can be different with header.Coinbase
// since clique algorithm can modify the coinbase field in header.
env, err := w.makeEnv(parent, header, genParams.coinbase)
env, err := w.makeEnv(parent, header, genParams.coinbase /*这个参数啥用??*/)
if err != nil {
log.Error("Failed to create sealing context", "err", err)
return nil, err
}
if header.ParentBeaconRoot != nil {
// 含义是什么??
context := core.NewEVMBlockContext(header, w.chain, nil, w.chainConfig, env.state)
vmenv := vm.NewEVM(context, vm.TxContext{}, env.state, w.chainConfig, vm.Config{})
core.ProcessBeaconBlockRoot(*header.ParentBeaconRoot, vmenv, env.state)
Expand Down Expand Up @@ -1290,7 +1293,7 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
filter.BlobFee = uint256.MustFromBig(eip4844.CalcBlobFee(*env.header.ExcessBlobGas))
}
filter.OnlyPlainTxs, filter.OnlyBlobTxs = true, false
pendingPlainTxs := w.eth.TxPool().Pending(filter)
pendingPlainTxs := w.eth.TxPool().Pending(filter) // filte txs from txpool

filter.OnlyPlainTxs, filter.OnlyBlobTxs = false, true
pendingBlobTxs := w.eth.TxPool().Pending(filter)
Expand All @@ -1302,7 +1305,7 @@ func (w *worker) fillTransactions(interrupt *atomic.Int32, env *environment) err
localPlainTxs, remotePlainTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingPlainTxs
localBlobTxs, remoteBlobTxs := make(map[common.Address][]*txpool.LazyTransaction), pendingBlobTxs

for _, account := range w.eth.TxPool().Locals() {
for _, account := range w.eth.TxPool().Locals() { // local pool
if txs := remotePlainTxs[account]; len(txs) > 0 {
delete(remotePlainTxs, account)
localPlainTxs[account] = txs
Expand Down Expand Up @@ -1358,6 +1361,7 @@ func (w *worker) estimateGasForTxDAG(env *environment) uint64 {
}

// generateWork generates a sealing block based on the given parameters.
// 重要,仔细看看
func (w *worker) generateWork(genParams *generateParams) *newPayloadResult {
// TODO delete after debug performance metrics
core.DebugInnerExecutionDuration = 0
Expand Down Expand Up @@ -1411,7 +1415,7 @@ func (w *worker) generateWork(genParams *generateParams) *newPayloadResult {
if interrupt == nil {
interrupt = new(atomic.Int32)
}
timer := time.AfterFunc(w.newpayloadTimeout, func() {
timer := time.AfterFunc(w.newpayloadTimeout /**/ /*这个参数*/, func() {
interrupt.Store(commitInterruptTimeout)
})
if w.config.Mev.MevEnabled {
Expand Down Expand Up @@ -1449,7 +1453,7 @@ func (w *worker) generateWork(genParams *generateParams) *newPayloadResult {
if w.chain.TxDAGEnabledWhenMine() {
work.state.MVStates().EnableAsyncGen()
}
err := w.fillTransactions(interrupt, work)
err := w.fillTransactions(interrupt /*这个很重要,外部可以中断内部的*/, work)
timer.Stop() // don't need timeout interruption any more
if errors.Is(err, errBlockInterruptedByTimeout) {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(w.newpayloadTimeout), "parentHash", genParams.parentHash)
Expand Down