Compare commits
2 Commits
stale-peer
...
v1.4.13
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26a4d4fda6 | ||
|
|
83a9b13771 |
@@ -1803,7 +1803,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
|
||||
}
|
||||
bc.hc.tdCache.Add(block.Hash(), externTd)
|
||||
bc.blockCache.Add(block.Hash(), block)
|
||||
bc.cacheReceipts(block.Hash(), receipts, block)
|
||||
bc.receiptsCache.Add(block.Hash(), receipts)
|
||||
if bc.chainConfig.IsCancun(block.Number(), block.Time()) {
|
||||
bc.sidecarsCache.Add(block.Hash(), block.Sidecars())
|
||||
}
|
||||
@@ -2320,6 +2320,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
|
||||
return it.index, err
|
||||
}
|
||||
|
||||
bc.cacheReceipts(block.Hash(), receipts, block)
|
||||
|
||||
// Update the metrics touched during block commit
|
||||
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
|
||||
storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them
|
||||
|
||||
@@ -4,10 +4,10 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/bohr"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/bruno"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/euler"
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/planck"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/plato"
|
||||
"github.com/ethereum/go-ethereum/core/systemcontracts/ramanujan"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
@@ -41,7 +40,7 @@ type Upgrade struct {
|
||||
Configs []*UpgradeConfig
|
||||
}
|
||||
|
||||
type upgradeHook func(blockNumber *big.Int, contractAddr common.Address, statedb vm.StateDB) error
|
||||
type upgradeHook func(blockNumber *big.Int, contractAddr common.Address, statedb *state.StateDB) error
|
||||
|
||||
const (
|
||||
mainNet = "Mainnet"
|
||||
@@ -790,11 +789,10 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.Int, lastBlockTime uint64, blockTime uint64, statedb vm.StateDB) {
|
||||
if config == nil || blockNumber == nil || statedb == nil || reflect.ValueOf(statedb).IsNil() {
|
||||
func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.Int, lastBlockTime uint64, blockTime uint64, statedb *state.StateDB) {
|
||||
if config == nil || blockNumber == nil || statedb == nil {
|
||||
return
|
||||
}
|
||||
|
||||
var network string
|
||||
switch GenesisHash {
|
||||
/* Add mainnet genesis hash */
|
||||
@@ -878,7 +876,7 @@ func UpgradeBuildInSystemContract(config *params.ChainConfig, blockNumber *big.I
|
||||
*/
|
||||
}
|
||||
|
||||
func applySystemContractUpgrade(upgrade *Upgrade, blockNumber *big.Int, statedb vm.StateDB, logger log.Logger) {
|
||||
func applySystemContractUpgrade(upgrade *Upgrade, blockNumber *big.Int, statedb *state.StateDB, logger log.Logger) {
|
||||
if upgrade == nil {
|
||||
logger.Info("Empty upgrade config", "height", blockNumber.String())
|
||||
return
|
||||
|
||||
@@ -2,13 +2,9 @@ package systemcontracts
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/vm"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -43,31 +39,3 @@ func TestAllCodesHash(t *testing.T) {
|
||||
allCodeHash := sha256.Sum256(allCodes)
|
||||
require.Equal(t, allCodeHash[:], common.Hex2Bytes("833cc0fc87c46ad8a223e44ccfdc16a51a7e7383525136441bd0c730f06023df"))
|
||||
}
|
||||
|
||||
func TestUpgradeBuildInSystemContractNilInterface(t *testing.T) {
|
||||
var (
|
||||
config = params.BSCChainConfig
|
||||
blockNumber = big.NewInt(37959559)
|
||||
lastBlockTime uint64 = 1713419337
|
||||
blockTime uint64 = 1713419340
|
||||
statedb vm.StateDB
|
||||
)
|
||||
|
||||
GenesisHash = params.BSCGenesisHash
|
||||
|
||||
UpgradeBuildInSystemContract(config, blockNumber, lastBlockTime, blockTime, statedb)
|
||||
}
|
||||
|
||||
func TestUpgradeBuildInSystemContractNilValue(t *testing.T) {
|
||||
var (
|
||||
config = params.BSCChainConfig
|
||||
blockNumber = big.NewInt(37959559)
|
||||
lastBlockTime uint64 = 1713419337
|
||||
blockTime uint64 = 1713419340
|
||||
statedb vm.StateDB = (*state.StateDB)(nil)
|
||||
)
|
||||
|
||||
GenesisHash = params.BSCGenesisHash
|
||||
|
||||
UpgradeBuildInSystemContract(config, blockNumber, lastBlockTime, blockTime, statedb)
|
||||
}
|
||||
|
||||
@@ -369,7 +369,6 @@ func newHandler(config *handlerConfig) (*handler, error) {
|
||||
}
|
||||
h.txFetcher = fetcher.NewTxFetcher(h.txpool.Has, addTxs, fetchTx, h.removePeer)
|
||||
h.chainSync = newChainSyncer(h)
|
||||
h.printPeerStatus()
|
||||
return h, nil
|
||||
}
|
||||
|
||||
@@ -1018,67 +1017,3 @@ func (h *handler) enableSyncedFeatures() {
|
||||
// h.chain.TrieDB().SetBufferSize(pathdb.DefaultBufferSize)
|
||||
// }
|
||||
}
|
||||
|
||||
type PeerDummy struct {
|
||||
ID string
|
||||
Head common.Hash
|
||||
TD *big.Int
|
||||
TimeStamp time.Time
|
||||
}
|
||||
|
||||
func (h *handler) printPeerStatus() {
|
||||
go func() {
|
||||
statusMap := make(map[string]PeerDummy)
|
||||
for {
|
||||
// run in timer very 1 minue of time
|
||||
time.Sleep(1 * time.Minute)
|
||||
// Create a set to track current peers
|
||||
currentPeers := make(map[string]struct{})
|
||||
// print peer status
|
||||
h.peers.lock.RLock()
|
||||
for _, peer := range h.peers.peers {
|
||||
currentPeers[peer.Peer.ID()] = struct{}{}
|
||||
head, td := peer.Peer.Head()
|
||||
if p, ok := statusMap[peer.Peer.ID()]; ok {
|
||||
if p.Head == head && p.TD.Cmp(td) == 0 {
|
||||
continue
|
||||
}
|
||||
p.Head = head
|
||||
p.TD = td
|
||||
p.TimeStamp = time.Now()
|
||||
statusMap[peer.Peer.ID()] = p
|
||||
} else {
|
||||
statusMap[peer.Peer.ID()] = PeerDummy{
|
||||
ID: peer.Peer.ID(),
|
||||
Head: head,
|
||||
TD: td,
|
||||
TimeStamp: time.Now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
h.peers.lock.RUnlock()
|
||||
|
||||
// Remove peers from statusMap that are no longer in h.peers.peers
|
||||
for id := range statusMap {
|
||||
if _, exists := currentPeers[id]; !exists {
|
||||
delete(statusMap, id)
|
||||
}
|
||||
}
|
||||
|
||||
var count int
|
||||
for _, peer := range statusMap {
|
||||
if peer.TimeStamp.Before(time.Now().Add(-60 * time.Minute)) {
|
||||
count++
|
||||
if count == 1 {
|
||||
log.Warn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
}
|
||||
log.Warn("peer", peer.ID, "head", peer.Head, "TD", peer.TD, "TimeStamp", peer.TimeStamp)
|
||||
}
|
||||
}
|
||||
if count > 0 {
|
||||
log.Warn("Total peers: ", len(statusMap), "inactive peers: ", count)
|
||||
log.Warn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user