From cc369cf1bbbb5b7c583d206bf529c0e5db552664 Mon Sep 17 00:00:00 2001 From: blxdyx <125243069+blxdyx@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:40:41 +0800 Subject: [PATCH] Update readme and fix ci (#512) --- README.md | 17 +++++++++++ cmd/state/exec3/state.go | 5 +++- consensus/aura/auraabi/gen_block_reward.go | 5 ++-- consensus/misc/eip4844.go | 32 +++++++++++++++++++-- consensus/parlia/feynmanfork.go | 4 +-- consensus/parlia/parlia.go | 12 ++++---- core/vm/contracts_lightclient.go | 13 +++++---- core/vm/lightclient/iavl/proof.go | 7 +++-- core/vm/lightclient/v2/lightclient.go | 7 +++-- eth/protocols/eth/protocol_test.go | 2 +- turbo/stages/headerdownload/header_algos.go | 2 +- 11 files changed, 79 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8883764d588..c397b25baa6 100644 --- a/README.md +++ b/README.md @@ -860,6 +860,23 @@ du -hsc /erigon/snapshots/* 4.1T /erigon/snapshots ``` +``` +# bsc-mainnet - archive - Sep 2024 + +du -hsc /erigon/* +327M /erigon/parlia +5.1G /erigon/chaindata +4.2T /erigon/snapshots +4.2T total + +du -hsc /erigon/snapshots/* +332G /erigon-data/snapshots/accessor +562G /erigon-data/snapshots/domain +882G /erigon-data/snapshots/history +1.3T /erigon-data/snapshots/idx +4.4T /erigon/snapshots +``` + ### E3 other perf trics - `--sync.loop.block.limit=10_000 --batchSize=2g` - likely will help for sync speed. diff --git a/cmd/state/exec3/state.go b/cmd/state/exec3/state.go index 327bee00e81..97f032b57e9 100644 --- a/cmd/state/exec3/state.go +++ b/cmd/state/exec3/state.go @@ -202,7 +202,10 @@ func (rw *Worker) RunTxTaskNoLock(txTask *state.TxTask, isMining bool) { rules := txTask.Rules var err error header := txTask.Header - lastBlockTime := header.Time - rw.chainConfig.Parlia.Period + var lastBlockTime uint64 + if rw.isPoSA { + lastBlockTime = header.Time - rw.chainConfig.Parlia.Period + } //fmt.Printf("txNum=%d blockNum=%d history=%t\n", txTask.TxNum, txTask.BlockNum, txTask.HistoryExecution) switch { diff --git a/consensus/aura/auraabi/gen_block_reward.go b/consensus/aura/auraabi/gen_block_reward.go index 0b1918fd00c..fccbe6bf29d 100644 --- a/consensus/aura/auraabi/gen_block_reward.go +++ b/consensus/aura/auraabi/gen_block_reward.go @@ -4,6 +4,7 @@ package auraabi import ( + "errors" "math/big" "strings" @@ -206,7 +207,7 @@ type RewardParams struct { // Solidity: function reward(address[] benefactors, uint16[] kind) returns(address[], uint256[]) func ParseReward(calldata []byte) (*RewardParams, error) { if len(calldata) <= 4 { - return nil, fmt.Errorf("invalid calldata input") + return nil, errors.New("invalid calldata input") } _abi, err := abi.JSON(strings.NewReader(BlockRewardABI)) @@ -223,7 +224,7 @@ func ParseReward(calldata []byte) (*RewardParams, error) { value := reflect.ValueOf(paramsResult).Elem() if value.NumField() != len(out) { - return nil, fmt.Errorf("failed to match calldata with param field number") + return nil, errors.New("failed to match calldata with param field number") } out0 := *abi.ConvertType(out[0], new([]libcommon.Address)).(*[]libcommon.Address) diff --git a/consensus/misc/eip4844.go b/consensus/misc/eip4844.go index aff753b4b9d..91e0910f705 100644 --- a/consensus/misc/eip4844.go +++ b/consensus/misc/eip4844.go @@ -78,6 +78,20 @@ func FakeExponential(factor, denom *uint256.Int, excessBlobGas uint64) (*uint256 // VerifyPresenceOfCancunHeaderFields checks that the fields introduced in Cancun (EIP-4844, EIP-4788) are present. func VerifyPresenceOfCancunHeaderFields(header *types.Header) error { + if header.BlobGasUsed == nil { + return errors.New("header is missing blobGasUsed") + } + if header.ExcessBlobGas == nil { + return errors.New("header is missing excessBlobGas") + } + if header.ParentBeaconBlockRoot == nil { + return errors.New("header is missing parentBeaconBlockRoot") + } + return nil +} + +// VerifyBscPresenceOfCancunHeaderFields checks that the fields introduced in Cancun (EIP-4844, EIP-4788) are present. +func VerifyBscPresenceOfCancunHeaderFields(header *types.Header) error { if header.BlobGasUsed == nil { return errors.New("header is missing blobGasUsed") } @@ -95,6 +109,20 @@ func VerifyPresenceOfCancunHeaderFields(header *types.Header) error { // VerifyAbsenceOfCancunHeaderFields checks that the header doesn't have any fields added in Cancun (EIP-4844, EIP-4788). func VerifyAbsenceOfCancunHeaderFields(header *types.Header) error { + if header.BlobGasUsed != nil { + return fmt.Errorf("invalid blobGasUsed before fork: have %v, expected 'nil'", header.BlobGasUsed) + } + if header.ExcessBlobGas != nil { + return fmt.Errorf("invalid excessBlobGas before fork: have %v, expected 'nil'", header.ExcessBlobGas) + } + if header.ParentBeaconBlockRoot != nil { + return fmt.Errorf("invalid parentBeaconBlockRoot before fork: have %v, expected 'nil'", header.ParentBeaconBlockRoot) + } + return nil +} + +// VerifyBscAbsenceOfCancunHeaderFields checks that the header doesn't have any fields added in Cancun (EIP-4844, EIP-4788). +func VerifyBscAbsenceOfCancunHeaderFields(header *types.Header) error { if header.BlobGasUsed != nil { return fmt.Errorf("invalid blobGasUsed before fork: have %v, expected 'nil'", header.BlobGasUsed) } @@ -113,10 +141,10 @@ func VerifyAbsenceOfCancunHeaderFields(header *types.Header) error { // VerifyPresenceOfBohrHeaderFields checks that the fields introduced in Cancun (EIP-4844, EIP-4788) are present. func VerifyPresenceOfBohrHeaderFields(header *types.Header) error { if header.BlobGasUsed == nil { - return fmt.Errorf("header is missing blobGasUsed") + return errors.New("header is missing blobGasUsed") } if header.ExcessBlobGas == nil { - return fmt.Errorf("header is missing excessBlobGas") + return errors.New("header is missing excessBlobGas") } if header.ParentBeaconBlockRoot == nil || *header.ParentBeaconBlockRoot != (libcommon.Hash{}) { return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected zero hash", header.ParentBeaconBlockRoot) diff --git a/consensus/parlia/feynmanfork.go b/consensus/parlia/feynmanfork.go index c487933e805..b33d7b7afa4 100644 --- a/consensus/parlia/feynmanfork.go +++ b/consensus/parlia/feynmanfork.go @@ -2,7 +2,7 @@ package parlia import ( "container/heap" - "fmt" + "errors" "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon-lib/kv/rawdbv3" "math/big" @@ -163,7 +163,7 @@ func (p *Parlia) getValidatorElectionInfo(header *types.Header, ibs *state.Intra return nil, err } if totalLength.Int64() != int64(len(validators)) || totalLength.Int64() != int64(len(votingPowers)) || totalLength.Int64() != int64(len(voteAddrs)) { - return nil, fmt.Errorf("validator length not match") + return nil, errors.New("validator length not match") } validatorItems := make([]ValidatorItem, len(validators)) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 4469e85abef..da8089e1889 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -494,7 +494,7 @@ func (p *Parlia) verifyVoteAttestation(chain consensus.ChainHeaderReader, header // The valid voted validators should be no less than 2/3 validators. if len(votedAddrs) < math.CeilDiv(len(snap.Validators)*2, 3) { - return fmt.Errorf("invalid attestation, not enough validators voted") + return errors.New("invalid attestation, not enough validators voted") } // Verify the aggregated signature. @@ -503,7 +503,7 @@ func (p *Parlia) verifyVoteAttestation(chain consensus.ChainHeaderReader, header return fmt.Errorf("BLS signature converts failed: %v", err) } if !aggSig.FastAggregateVerify(votedAddrs, attestation.Data.Hash()) { - return fmt.Errorf("invalid attestation, signature verify failed") + return errors.New("invalid attestation, signature verify failed") } return nil @@ -583,7 +583,7 @@ func (p *Parlia) verifyHeader(chain consensus.ChainHeaderReader, header *types.H // Verify the existence / non-existence of excessBlobGas cancun := chain.Config().IsCancun(header.Number.Uint64(), header.Time) if !cancun { - if err := misc.VerifyAbsenceOfCancunHeaderFields(header); err != nil { + if err := misc.VerifyBscAbsenceOfCancunHeaderFields(header); err != nil { return err } } else { @@ -593,7 +593,7 @@ func (p *Parlia) verifyHeader(chain consensus.ChainHeaderReader, header *types.H return err } } else { - if err := misc.VerifyPresenceOfCancunHeaderFields(header); err != nil { + if err := misc.VerifyBscPresenceOfCancunHeaderFields(header); err != nil { return err } } @@ -1491,10 +1491,10 @@ func (p *Parlia) applyTransaction(from libcommon.Address, to libcommon.Address, expectedTx := types.Transaction(types.NewTransaction(actualTx.GetNonce(), to, value, math.MaxUint64/2, u256.Num0, data)) expectedHash := expectedTx.SigningHash(p.chainConfig.ChainID) if len(*systemTxs) == 0 { - return false, fmt.Errorf("supposed to get a actual transaction, but get none") + return false, errors.New("supposed to get a actual transaction, but get none") } if actualTx == nil { - return false, fmt.Errorf("supposed to get a actual transaction, but get nil") + return false, errors.New("supposed to get a actual transaction, but get nil") } actualHash := actualTx.SigningHash(p.chainConfig.ChainID) if !bytes.Equal(actualHash.Bytes(), expectedHash.Bytes()) { diff --git a/core/vm/contracts_lightclient.go b/core/vm/contracts_lightclient.go index de93b06ba8b..c9608fdd437 100644 --- a/core/vm/contracts_lightclient.go +++ b/core/vm/contracts_lightclient.go @@ -2,6 +2,7 @@ package vm import ( "encoding/binary" + "errors" "fmt" "github.com/tendermint/tendermint/crypto/secp256k1" "net/url" @@ -67,7 +68,7 @@ func (c *tmHeaderValidate) Run(input []byte) (result []byte, err error) { }() if uint64(len(input)) <= precompileContractInputMetaDataLength { - return nil, fmt.Errorf("invalid input") + return nil, errors.New("invalid input") } payloadLength := binary.BigEndian.Uint64(input[precompileContractInputMetaDataLength-uint64TypeLength : precompileContractInputMetaDataLength]) @@ -131,7 +132,7 @@ func (c *tmHeaderValidateNano) RequiredGas(input []byte) uint64 { } func (c *tmHeaderValidateNano) Run(input []byte) (result []byte, err error) { - return nil, fmt.Errorf("suspend") + return nil, errors.New("suspend") } type iavlMerkleProofValidateNano struct{} @@ -141,7 +142,7 @@ func (c *iavlMerkleProofValidateNano) RequiredGas(_ []byte) uint64 { } func (c *iavlMerkleProofValidateNano) Run(_ []byte) (result []byte, err error) { - return nil, fmt.Errorf("suspend") + return nil, errors.New("suspend") } // ------------------------------------------------------------------------------------------------------------------------------------------------ @@ -250,7 +251,7 @@ func (c *basicIavlMerkleProofValidate) Run(input []byte) (result []byte, err err valid := kvmp.Validate() if !valid { - return nil, fmt.Errorf("invalid merkle proof") + return nil, errors.New("invalid merkle proof") } return successfulMerkleResult(), nil @@ -418,7 +419,7 @@ const ( // | 33 bytes | 64 bytes | 32 bytes | func (c *secp256k1SignatureRecover) Run(input []byte) (result []byte, err error) { if len(input) != int(secp256k1PubKeyLength)+int(secp256k1SignatureLength)+int(secp256k1SignatureMsgHashLength) { - return nil, fmt.Errorf("invalid input") + return nil, errors.New("invalid input") } return c.runTMSecp256k1Signature( @@ -432,7 +433,7 @@ func (c *secp256k1SignatureRecover) runTMSecp256k1Signature(pubkey, signatureStr tmPubKey := secp256k1.PubKeySecp256k1(pubkey) ok := tmPubKey.VerifyBytesWithMsgHash(msgHash, signatureStr) if !ok { - return nil, fmt.Errorf("invalid signature") + return nil, errors.New("invalid signature") } return tmPubKey.Address().Bytes(), nil } diff --git a/core/vm/lightclient/iavl/proof.go b/core/vm/lightclient/iavl/proof.go index 585c9748823..9dc3c39ced3 100644 --- a/core/vm/lightclient/iavl/proof.go +++ b/core/vm/lightclient/iavl/proof.go @@ -2,6 +2,7 @@ package iavl import ( "bytes" + "errors" "fmt" "github.com/tendermint/go-amino" @@ -11,13 +12,13 @@ import ( var ( // ErrInvalidProof is returned by Verify when a proof cannot be validated. - ErrInvalidProof = fmt.Errorf("invalid proof") + ErrInvalidProof = errors.New("invalid proof") // ErrInvalidInputs is returned when the inputs passed to the function are invalid. - ErrInvalidInputs = fmt.Errorf("invalid inputs") + ErrInvalidInputs = errors.New("invalid inputs") // ErrInvalidRoot is returned when the root passed in does not match the proof's. - ErrInvalidRoot = fmt.Errorf("invalid root") + ErrInvalidRoot = errors.New("invalid root") ) //---------------------------------------- diff --git a/core/vm/lightclient/v2/lightclient.go b/core/vm/lightclient/v2/lightclient.go index 002426e4214..00e49e17128 100644 --- a/core/vm/lightclient/v2/lightclient.go +++ b/core/vm/lightclient/v2/lightclient.go @@ -4,6 +4,7 @@ package v2 import ( "bytes" "encoding/binary" + "errors" "fmt" "github.com/cometbft/cometbft/crypto/ed25519" @@ -49,7 +50,7 @@ func (cs ConsensusState) EncodeConsensusState() ([]byte, error) { pos := uint64(0) if uint64(len(cs.ChainID)) > chainIDLength { - return nil, fmt.Errorf("chainID length should be no more than 32") + return nil, errors.New("chainID length should be no more than 32") } copy(encodingBytes[pos:pos+chainIDLength], cs.ChainID) pos += chainIDLength @@ -64,7 +65,7 @@ func (cs ConsensusState) EncodeConsensusState() ([]byte, error) { validator := cs.ValidatorSet.Validators[index] pubkey, ok := validator.PubKey.(ed25519.PubKey) if !ok { - return nil, fmt.Errorf("invalid pubkey type") + return nil, errors.New("invalid pubkey type") } copy(encodingBytes[pos:pos+validatorPubkeyLength], pubkey[:]) @@ -195,7 +196,7 @@ func DecodeConsensusState(input []byte) (ConsensusState, error) { // 32 bytes | | | func DecodeLightBlockValidationInput(input []byte) (*ConsensusState, *types.LightBlock, error) { if uint64(len(input)) <= consensusStateLengthBytesLength { - return nil, nil, fmt.Errorf("invalid input") + return nil, nil, errors.New("invalid input") } csLen := binary.BigEndian.Uint64(input[consensusStateLengthBytesLength-uint64TypeLength : consensusStateLengthBytesLength]) diff --git a/eth/protocols/eth/protocol_test.go b/eth/protocols/eth/protocol_test.go index b1d64ebee21..6dc0ff2b80e 100644 --- a/eth/protocols/eth/protocol_test.go +++ b/eth/protocols/eth/protocol_test.go @@ -317,6 +317,6 @@ func TestNewBlockPacket_EncodeDecode(t *testing.T) { var actual NewBlockPacket err = rlp.DecodeBytes(enc, &actual) require.NoError(t, err) - require.Equal(t, item.msg, actual) + require.DeepEqual(t, item.msg, actual) } } diff --git a/turbo/stages/headerdownload/header_algos.go b/turbo/stages/headerdownload/header_algos.go index f4f239bc982..222a6cfe83f 100644 --- a/turbo/stages/headerdownload/header_algos.go +++ b/turbo/stages/headerdownload/header_algos.go @@ -1156,7 +1156,7 @@ func (hd *HeaderDownload) ProcessHeader(sh ChainSegmentHeader, newBlock bool, pe func (hd *HeaderDownload) ProcessHeaders(csHeaders []ChainSegmentHeader, newBlock bool, peerID [64]byte) bool { requestMore := false for _, sh := range csHeaders { - if sh.Number > uint64(hd.loopBlockLimit)+hd.highestInDb { + if hd.loopBlockLimit != 0 && sh.Number > uint64(hd.loopBlockLimit)+hd.highestInDb { continue } // Lock is acquired for every invocation of ProcessHeader