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

fix: Prague code merge geth-v1.14.12 CI fix #58

Merged
merged 10 commits into from
Dec 9, 2024
Merged
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
17 changes: 7 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
golang-lint:
strategy:
matrix:
go-version: [1.21.x]
go-version: [1.23.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -47,12 +47,9 @@ jobs:
go mod tidy
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.55.2
working-directory: ./
skip-pkg-cache: true
skip-cache: true
skip-build-cache: true
args: --timeout=99m --config ./.golangci.yml
env:
CGO_CFLAGS: "-O -D__BLST_PORTABLE__"
CGO_CFLAGS_ALLOW: "-O -D__BLST_PORTABLE__"
ANDROID_HOME: "" # Skip android test
run: |
make lint
76 changes: 74 additions & 2 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/gopool"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand All @@ -51,6 +52,8 @@ const (
checkpointInterval = 1024 // Number of blocks after which to save the vote snapshot to the database
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
inmemorySignatures = 4096 // Number of recent block signatures to keep in memory

wiggleTime = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers
)

// Clique proof-of-authority protocol constants.
Expand Down Expand Up @@ -139,6 +142,9 @@ var (
errRecentlySigned = errors.New("recently signed")
)

// SignerFn hashes and signs the data to be signed by a backing account.
type SignerFn func(signer accounts.Account, mimeType string, message []byte) ([]byte, error)

// ecrecover extracts the Ethereum account address from a signed header.
func ecrecover(header *types.Header, sigcache *sigLRU) (common.Address, error) {
// If the signature's already cached, return that
Expand Down Expand Up @@ -176,6 +182,7 @@ type Clique struct {
proposals map[common.Address]bool // Current list of proposals we are pushing

signer common.Address // Ethereum address of the signing key
signFn SignerFn // Signer function to authorize hashes with
lock sync.RWMutex // Protects the signer and proposals fields

// The fields below are for testing only
Expand Down Expand Up @@ -604,11 +611,12 @@ func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *

// Authorize injects a private key into the consensus engine to mint new blocks
// with.
func (c *Clique) Authorize(signer common.Address) {
func (c *Clique) Authorize(signer common.Address, signFn SignerFn) {
c.lock.Lock()
defer c.lock.Unlock()

c.signer = signer
c.signFn = signFn
}

func (c *Clique) Delay(chain consensus.ChainReader, header *types.Header, leftOver *time.Duration) *time.Duration {
Expand All @@ -618,7 +626,71 @@ func (c *Clique) Delay(chain consensus.ChainReader, header *types.Header, leftOv
// Seal implements consensus.Engine, attempting to create a sealed block using
// the local signing credentials.
func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
panic("clique (poa) sealing not supported any more")
header := block.Header()

// Sealing the genesis block is not supported
number := header.Number.Uint64()
if number == 0 {
return errUnknownBlock
}
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
if c.config.Period == 0 && len(block.Transactions()) == 0 {
return errors.New("sealing paused while waiting for transactions")
}
// Don't hold the signer fields for the entire sealing procedure
c.lock.RLock()
signer, signFn := c.signer, c.signFn
c.lock.RUnlock()

// Bail out if we're unauthorized to sign a block
snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
if err != nil {
return err
}
if _, authorized := snap.Signers[signer]; !authorized {
return errUnauthorizedSigner
}
// If we're amongst the recent signers, wait for the next block
for seen, recent := range snap.Recents {
if recent == signer {
// Signer is among recents, only wait if the current block doesn't shift it out
if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit {
return errors.New("signed recently, must wait for others")
}
}
}
// Sweet, the protocol permits us to sign the block, wait for our time
delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple
if header.Difficulty.Cmp(diffNoTurn) == 0 {
// It's not our turn explicitly to sign, delay it a bit
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
delay += time.Duration(rand.Int63n(int64(wiggle)))

log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
}
// Sign all the things!
sighash, err := signFn(accounts.Account{Address: signer}, accounts.MimetypeClique, CliqueRLP(header))
if err != nil {
return err
}
copy(header.Extra[len(header.Extra)-extraSeal:], sighash)
// Wait until sealing is terminated or delay timeout.
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
gopool.Submit(func() {
select {
case <-stop:
return
case <-time.After(delay):
}

select {
case results <- block.WithSeal(header):
default:
log.Warn("Sealing result is not read by miner", "sealhash", SealHash(header))
}
})

return nil
}

// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty
Expand Down
19 changes: 9 additions & 10 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"runtime"
"slices"
"sort"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -346,16 +347,14 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
}
systemcontracts.GenesisHash = genesisHash
log.Info("Initialised chain configuration", "config", chainConfig)
// Description of chainConfig is empty now
/*
log.Info("")
log.Info(strings.Repeat("-", 153))
for _, line := range strings.Split(chainConfig.Description(), "\n") {
log.Info(line)
}
log.Info(strings.Repeat("-", 153))
log.Info("")
*/

log.Info("")
log.Info(strings.Repeat("-", 153))
for _, line := range strings.Split(chainConfig.Description(), "\n") {
log.Info(line)
}
log.Info(strings.Repeat("-", 153))
log.Info("")

bc := &BlockChain{
chainConfig: chainConfig,
Expand Down
12 changes: 6 additions & 6 deletions core/blockchain_notries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,17 @@ func TestFastNode(t *testing.T) {
// test full mode and succeed
_, fastnode, blocks, err := makeTestBackendWithRemoteValidator(2048, FullVerify, nil)
if err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
_, err = fastnode.chain.InsertChain(blocks)
if err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
// test full mode and failed
failed := &verifFailedStatus{status: types.StatusDiffHashMismatch, blockNumber: 204}
_, fastnode, blocks, err = makeTestBackendWithRemoteValidator(2048, FullVerify, failed)
if err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
_, err = fastnode.chain.InsertChain(blocks)
if err == nil || fastnode.chain.CurrentBlock().Number.Uint64() != failed.blockNumber+10 {
Expand All @@ -207,17 +207,17 @@ func TestFastNode(t *testing.T) {
// test insecure mode and succeed
_, fastnode, blocks, err = makeTestBackendWithRemoteValidator(2048, InsecureVerify, nil)
if err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
_, err = fastnode.chain.InsertChain(blocks)
if err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
// test insecure mode and failed
failed = &verifFailedStatus{status: types.StatusImpossibleFork, blockNumber: 204}
_, fastnode, blocks, err = makeTestBackendWithRemoteValidator(2048, FullVerify, failed)
if err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
_, err = fastnode.chain.InsertChain(blocks)
if err == nil || fastnode.chain.CurrentBlock().Number.Uint64() != failed.blockNumber+10 {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/accessors_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func TestBlockBlobSidecarsStorage(t *testing.T) {
t.Fatalf("no sidecars returned")
} else {
if err := checkBlobSidecarsRLP(bs, sidecars); err != nil {
t.Fatalf(err.Error())
t.Fatalf("err: %v", err.Error())
}
}

Expand Down
6 changes: 5 additions & 1 deletion core/verkle_witness_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
)

var (
//nolint:unused
testVerkleChainConfig = &params.ChainConfig{
ChainID: big.NewInt(1),
HomesteadBlock: big.NewInt(0),
Expand Down Expand Up @@ -80,7 +81,10 @@ var (
}
)

func TestProcessVerkle(t *testing.T) {
// TODO(Nathan): fix before verkle enabled
//
//nolint:unused
func testProcessVerkle(t *testing.T) {
var (
code = common.FromHex(`6060604052600a8060106000396000f360606040526008565b00`)
intrinsicContractCreationGas, _ = IntrinsicGas(code, nil, true, true, true, true)
Expand Down
2 changes: 1 addition & 1 deletion eth/fetcher/block_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func (f *BlockFetcher) loop() {
log.Trace("Fetching scheduled headers", "peer", peer, "list", hashes)

// Create a closure of the fetch and schedule in on a new thread
fetchHeader, hashes := f.fetching[hashes[0]].fetchHeader, hashes
fetchHeader := f.fetching[hashes[0]].fetchHeader

go func(peer string) {
if f.fetchingHook != nil {
Expand Down
3 changes: 0 additions & 3 deletions eth/handler_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,6 @@ func testBroadcastBlock(t *testing.T, peers, bcasts int) {
td = source.chain.GetTd(genesis.Hash(), genesis.NumberU64())
)
for i, sink := range sinks {
sink := sink // Closure for gorotuine below

sourcePipe, sinkPipe := p2p.MsgPipe()
defer sourcePipe.Close()
defer sinkPipe.Close()
Expand Down Expand Up @@ -653,7 +651,6 @@ func testBroadcastBlock(t *testing.T, peers, bcasts int) {
// Iterate through all the sinks and ensure the correct number got the block
done := make(chan struct{}, peers)
for _, ch := range blockChs {
ch := ch
go func() {
<-ch
done <- struct{}{}
Expand Down
2 changes: 0 additions & 2 deletions eth/protocols/bsc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ type Backend interface {
func MakeProtocols(backend Backend) []p2p.Protocol {
protocols := make([]p2p.Protocol, len(ProtocolVersions))
for i, version := range ProtocolVersions {
version := version // Closure

protocols[i] = p2p.Protocol{
Name: ProtocolName,
Version: version,
Expand Down
1 change: 0 additions & 1 deletion eth/protocols/eth/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,6 @@ func TestHandleNewBlock(t *testing.T) {

// Run the tests
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := handleNewBlock(backend, tc.msg, localEth)
if err != tc.err {
Expand Down
2 changes: 0 additions & 2 deletions eth/protocols/trust/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ type Backend interface {
func MakeProtocols(backend Backend) []p2p.Protocol {
protocols := make([]p2p.Protocol, len(ProtocolVersions))
for i, version := range ProtocolVersions {
version := version // Closure

protocols[i] = p2p.Protocol{
Name: ProtocolName,
Version: version,
Expand Down
19 changes: 9 additions & 10 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,6 @@ func TestFillBlobTransaction(t *testing.T) {
},
}
for _, tc := range suite {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -3397,55 +3396,55 @@ func TestRPCGetBlobSidecars(t *testing.T) {
fullBlob bool
file string
}{
// 1. block without any txs(number)
// 0. block without any txs(number)
{
test: rpc.BlockNumberOrHashWithNumber(0),
fullBlob: true,
file: "number-1",
},
// 2. earliest tag
// 1. earliest tag
{
test: rpc.BlockNumberOrHashWithNumber(rpc.EarliestBlockNumber),
fullBlob: true,
file: "tag-earliest",
},
// 3. latest tag
// 2. latest tag
{
test: rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber),
fullBlob: true,
file: "tag-latest",
},
// 4. block is empty
// 3. block is empty
{
test: rpc.BlockNumberOrHashWithHash(common.Hash{}, false),
fullBlob: true,
file: "hash-empty",
},
// 5. block is not found
// 4. block is not found
{
test: rpc.BlockNumberOrHashWithHash(common.HexToHash("deadbeef"), false),
fullBlob: true,
file: "hash-notfound",
},
// 6. block is not found
// 5. block is not found
{
test: rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(genBlocks + 1)),
fullBlob: true,
file: "block-notfound",
},
// 7. block with blob tx
// 6. block with blob tx
{
test: rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(6)),
fullBlob: true,
file: "block-with-blob-tx",
},
// 8. block with sidecar
// 7. block with sidecar
{
test: rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(7)),
fullBlob: true,
file: "block-with-blobSidecars",
},
// 9. block with sidecar but show little
// 8. block with sidecar but show little
{
test: rpc.BlockNumberOrHashWithNumber(rpc.BlockNumber(7)),
fullBlob: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"0xc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
]
},
"blockHash": "0x6fe5e7eea22c44f700c95da066d6e0740894b6c1e993825cc63f634ad4f74250",
"blockHash": "0x22c19d38b338157697f939991a74da4129c53e196517a9aa8077f5246716fb0a",
"blockNumber": "0x7",
"txHash": "0xc520427e696154779f6b21ab03a0735769e1c029035a484f5876f60383a0a7ce",
"txIndex": "0x0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"0xc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
]
},
"blockHash": "0x6fe5e7eea22c44f700c95da066d6e0740894b6c1e993825cc63f634ad4f74250",
"blockHash": "0x22c19d38b338157697f939991a74da4129c53e196517a9aa8077f5246716fb0a",
"blockNumber": "0x7",
"txHash": "0xc520427e696154779f6b21ab03a0735769e1c029035a484f5876f60383a0a7ce",
"txIndex": "0x0"
Expand Down
Loading
Loading