2021-03-23 09:00:07 +00:00
|
|
|
package ethutils
|
|
|
|
|
|
|
|
import (
|
2023-01-13 18:12:18 +00:00
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
|
|
|
"github.com/ledgerwatch/log/v3"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/consensus"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
2021-03-23 09:00:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// IsLocalBlock checks whether the specified block is mined
|
|
|
|
// by local miner accounts.
|
|
|
|
//
|
|
|
|
// We regard two types of accounts as local miner account: etherbase
|
|
|
|
// and accounts specified via `txpool.locals` flag.
|
2023-01-13 18:12:18 +00:00
|
|
|
func IsLocalBlock(engine consensus.Engine, etherbase libcommon.Address, txPoolLocals []libcommon.Address, header *types.Header) bool {
|
2021-03-23 09:00:07 +00:00
|
|
|
author, err := engine.Author(header)
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Failed to retrieve block author", "number", header.Number, "header_hash", header.Hash(), "err", err)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// Check whether the given address is etherbase.
|
|
|
|
if author == etherbase {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
// Check whether the given address is specified by `txpool.local`
|
|
|
|
// CLI flag.
|
|
|
|
for _, account := range txPoolLocals {
|
|
|
|
if account == author {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|