Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/bump-version-to-1.5.0' i…
Browse files Browse the repository at this point in the history
…nto feature/bump-version-to-1.5.1
  • Loading branch information
cheng762 committed Oct 30, 2023
2 parents 1268c70 + a22f9df commit 02998bf
Show file tree
Hide file tree
Showing 26 changed files with 293 additions and 235 deletions.
4 changes: 2 additions & 2 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritica
break
}
if freeSpace < freeDiskSpaceCritical {
log.Error("Low disk space. Gracefully shutting down Geth to prevent database corruption.", "available", common.StorageSize(freeSpace))
log.Error("Low disk space. Gracefully shutting down PlatON to prevent database corruption.", "available", common.StorageSize(freeSpace))
sigc <- syscall.SIGTERM
break
} else if freeSpace < 2*freeDiskSpaceCritical {
log.Warn("Disk space is running low. Geth will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical))
log.Warn("Disk space is running low. PlatON will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical))
}
time.Sleep(60 * time.Second)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ var (
Usage: "Time interval to regenerate the trie cache journal",
Value: ethconfig.Defaults.TrieCleanCacheRejournal,
}
SnapshotFlag = cli.BoolTFlag{
SnapshotFlag = cli.BoolFlag{
Name: "snapshot",
Usage: `Enables snapshot-database mode (default = enable)`,
Usage: `Enables snapshot-database mode`,
}
BloomFilterSizeFlag = cli.Uint64Flag{
Name: "bloomfilter.size",
Expand Down
1 change: 1 addition & 0 deletions common/vm/inner_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
DelegateRewardPoolAddr = common.HexToAddress("0x1000000000000000000000000000000000000006") // The PlatON Precompiled contract addr for delegate reward
ValidatorInnerContractAddr = common.HexToAddress("0x2000000000000000000000000000000000000000") // The PlatON Precompiled contract addr for cbft inner
VrfInnerContractAddr = common.HexToAddress("0x3000000000000000000000000000000000000001") // The PlatON Precompiled contract addr for vrf inner
BlsVerifyContractAddr = common.HexToAddress("0x3000000000000000000000000000000000000002") // The PlatON Precompiled contract addr for bls verify
)

type PrecompiledContractCheck interface {
Expand Down
60 changes: 4 additions & 56 deletions consensus/bft_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (bm *BftMock) Author(header *types.Header) (common.Address, error) {
// VerifyHeader checks whether a header conforms to the consensus rules of a
// given engine. Verifying the seal may be done optionally here, or explicitly
// via the VerifySeal method.
func (bm *BftMock) VerifyHeader(chain ChainReader, header *types.Header, seal bool) error {
func (bm *BftMock) VerifyHeader(chain ChainReader, header *types.Header, async bool) error {
if bm.fakeFail == header.Number.Uint64() {
return fmt.Errorf("failed verifyHeader on bftMock")
}
Expand Down Expand Up @@ -292,48 +292,11 @@ func (bm *BftMock) ShouldSeal(curTime time.Time) (bool, error) {
return true, nil
}

// OnBlockSignature received a new block signature
// Need to verify if the signature is signed by nodeID
func (bm *BftMock) OnBlockSignature(chain ChainReader, nodeID enode.IDv0, sig *cbfttypes.BlockSignature) error {
return nil
}

// OnNewBlock processes the BFT signatures
func (bm *BftMock) OnNewBlock(chain ChainReader, block *types.Block) error {
return nil
}

// OnPong processes the BFT signatures
func (bm *BftMock) OnPong(nodeID enode.IDv0, netLatency int64) error {
return nil

}

// OnBlockSynced sends a signal if a block synced from other peer.
func (bm *BftMock) OnBlockSynced() {

}

// CheckConsensusNode is a fake interface, no need to implement.
func (bm *BftMock) CheckConsensusNode(nodeID enode.IDv0) (bool, error) {
return true, nil
}

// IsConsensusNode is a fake interface, no need to implement.
func (bm *BftMock) IsConsensusNode() bool {
return true
}

// HighestLogicalBlock is a fake interface, no need to implement.
func (bm *BftMock) HighestLogicalBlock() *types.Block {
return nil
}

// HighestConfirmedBlock is a fake interface, no need to implement.
func (bm *BftMock) HighestConfirmedBlock() *types.Block {
return nil
}

// GetBlock is a fake interface, no need to implement.
func (bm *BftMock) GetBlock(hash common.Hash, number uint64) *types.Block {
return nil
Expand Down Expand Up @@ -364,32 +327,17 @@ func (bm *BftMock) GetBlockByHashAndNum(hash common.Hash, number uint64) *types.
return nil
}

// Status is a fake interface, no need to implement.
func (bm *BftMock) Status() string {
return ""
}

// CurrentBlock is a fake interface, no need to implement.
func (bm *BftMock) CurrentBlock() *types.Block {
//if len(bm.Blocks) == 0 {
// h := types.Header{Number: big.NewInt(0)}
// return types.NewBlockWithHeader(&h)
//}
//return bm.Blocks[len(bm.Blocks)-1]
return bm.Current
}

// TracingSwitch is a fake interface, no need to implement.
func (bm *BftMock) TracingSwitch(flag int8) {

}
func (bm *BftMock) TracingSwitch(flag int8) {}

func (bm *BftMock) Pause() {
func (bm *BftMock) Pause() {}

}
func (bm *BftMock) Resume() {

}
func (bm *BftMock) Resume() {}

func (bm *BftMock) Syncing() bool {
return false
Expand Down
30 changes: 27 additions & 3 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func (cbft *Cbft) Author(header *types.Header) (common.Address, error) {
return header.Coinbase, nil
}

func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error {
func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header, async bool) error {
// Short circuit if the header is known, or its parent not
number := header.Number.Uint64()
if chain.GetHeader(header.Hash(), number) != nil {
Expand All @@ -650,7 +650,12 @@ func (cbft *Cbft) VerifyHeader(chain consensus.ChainReader, header *types.Header

parent := chain.GetHeader(header.ParentHash, number-1)
if parent == nil {
parentBlock := cbft.GetBlockWithoutLock(header.ParentHash, number-1)
var parentBlock *types.Block
if async {
parentBlock = cbft.GetBlockWithLock(header.ParentHash, number-1)
} else {
parentBlock = cbft.GetBlockWithoutLock(header.ParentHash, number-1)
}
if parentBlock != nil {
parent = parentBlock.Header()
}
Expand Down Expand Up @@ -738,7 +743,7 @@ func (cbft *Cbft) verifyHeaderWorker(chain consensus.ChainReader, headers []*typ
if index == 0 {
parent = chain.GetHeader(headers[0].ParentHash, headers[0].Number.Uint64()-1)
if parent == nil {
parentBlock := cbft.GetBlockWithoutLock(headers[0].ParentHash, headers[0].Number.Uint64()-1)
parentBlock := cbft.GetBlockWithLock(headers[0].ParentHash, headers[0].Number.Uint64()-1)
if parentBlock != nil {
parent = parentBlock.Header()
}
Expand Down Expand Up @@ -1312,6 +1317,25 @@ func (cbft *Cbft) GetBlock(hash common.Hash, number uint64) *types.Block {
return <-result
}

// GetBlockWithLock synchronously obtains blocks according to the specified number and hash.
func (cbft *Cbft) GetBlockWithLock(hash common.Hash, number uint64) *types.Block {
result := make(chan *types.Block, 1)

cbft.asyncCallCh <- func() {
block, _ := cbft.blockTree.FindBlockAndQC(hash, number)
if block == nil {
if eb := cbft.state.FindBlock(hash, number); eb != nil {
block = eb
} else {
cbft.log.Debug("Get block failed", "hash", hash, "number", number)
}
}
result <- block
}

return <-result
}

// GetBlockWithoutLock returns the block corresponding to the specified number and hash.
func (cbft *Cbft) GetBlockWithoutLock(hash common.Hash, number uint64) *types.Block {
block, _ := cbft.blockTree.FindBlockAndQC(hash, number)
Expand Down
6 changes: 6 additions & 0 deletions consensus/cbft/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *even

isValidatorAfter := vp.isValidator(epoch, vp.nodeID)

nodes := make(map[enode.ID]struct{})
for _, validator := range vp.currentValidators.Nodes {
nodes[validator.NodeID] = struct{}{}
}
eventMux.Post(cbfttypes.UpdateValidatorEvent{Nodes: nodes})

if isValidatorBefore {
// If we are still a consensus node, that adding
// new validators as consensus peer, and removing
Expand Down
2 changes: 1 addition & 1 deletion consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type Engine interface {
// VerifyHeader checks whether a header conforms to the consensus rules of a
// given engine. Verifying the seal may be done optionally here, or explicitly
// via the VerifySeal method.
VerifyHeader(chain ChainReader, header *types.Header, seal bool) error
VerifyHeader(chain ChainReader, header *types.Header, async bool) error

// VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers
// concurrently. The method returns a quit channel to abort the operations and
Expand Down
5 changes: 3 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1538,13 +1538,14 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
headers[i] = block.Header()
seals[i] = verifySeals
}
abort, results := bc.engine.VerifyHeaders(bc, headers, seals)
defer close(abort)

// Pause engine
bc.engine.Pause()
defer bc.engine.Resume()

abort, results := bc.engine.VerifyHeaders(bc, headers, seals)
defer close(abort)

// Peek the error for the first block to decide the directing import logic
it := newInsertIterator(chain, results, bc.Validator())
block, err := it.next()
Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (bcr *BlockChainReactor) EndBlocker(header *types.Header, state xcom.StateD

func (bcr *BlockChainReactor) VerifyTx(tx *types.Transaction, to common.Address, rules params.Rules) error {

if !vm.IsPlatONPrecompiledContract(to, rules) {
if !vm.IsPlatONPrecompiledContract(to, rules, false) {
return nil
}

Expand Down
45 changes: 3 additions & 42 deletions core/cbfttypes/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"math"
"math/big"
"sort"

"github.com/PlatONnetwork/PlatON-Go/common/hexutil"
Expand All @@ -38,24 +37,6 @@ import (
"github.com/PlatONnetwork/PlatON-Go/crypto/bls"
)

// Block's Signature info
type BlockSignature struct {
SignHash common.Hash // Signature hash,header[0:32]
Hash common.Hash // Block hash,header[:]
Number *big.Int
Signature *common.BlockConfirmSign
}

func (bs *BlockSignature) Copy() *BlockSignature {
sign := *bs.Signature
return &BlockSignature{
SignHash: bs.SignHash,
Hash: bs.Hash,
Number: new(big.Int).Set(bs.Number),
Signature: &sign,
}
}

type UpdateChainStateFn func(qcState, lockState, commitState *protocols.State)

type CbftResult struct {
Expand All @@ -65,28 +46,6 @@ type CbftResult struct {
ChainStateUpdateCB func()
}

type ProducerState struct {
count int
miner common.Address
}

func (ps *ProducerState) Add(miner common.Address) {
if ps.miner == miner {
ps.count++
} else {
ps.miner = miner
ps.count = 1
}
}

func (ps *ProducerState) Get() (common.Address, int) {
return ps.miner, ps.count
}

func (ps *ProducerState) Validate(period int) bool {
return ps.count < period
}

type AddValidatorEvent struct {
Node *enode.Node
}
Expand All @@ -95,7 +54,9 @@ type RemoveValidatorEvent struct {
Node *enode.Node
}

type UpdateValidatorEvent struct{}
type UpdateValidatorEvent struct {
Nodes map[enode.ID]struct{}
}

type ValidateNode struct {
Index uint32 `json:"index"`
Expand Down
10 changes: 0 additions & 10 deletions core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package core

import (
"github.com/PlatONnetwork/PlatON-Go/common"
"github.com/PlatONnetwork/PlatON-Go/core/cbfttypes"
"github.com/PlatONnetwork/PlatON-Go/core/types"
)

Expand All @@ -28,15 +27,6 @@ type NewTxsEvent struct{ Txs []*types.Transaction }
// NewMinedBlockEvent is posted when a block has been imported.
type NewMinedBlockEvent struct{ Block *types.Block }

type PrepareMinedBlockEvent struct {
Block *types.Block
// ConsensusNodes []discover.NodeID
}
type BlockSignatureEvent struct {
BlockSignature *cbfttypes.BlockSignature
// ConsensusNodes []discover.NodeID
}

// RemovedLogsEvent is posted when a reorg happens
type RemovedLogsEvent struct{ Logs []*types.Log }

Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {

// Verify inner contract tx
if nil != tx.To() {
if err := bcr.VerifyTx(tx, *(tx.To()), pool.chainconfig.Rules(pool.chainconfig.NewtonBlock)); nil != err {
if err := bcr.VerifyTx(tx, *(tx.To()), pool.chainconfig.Rules(pool.resetHead.Number())); nil != err {
log.Error("Failed to verify tx", "txHash", tx.Hash().Hex(), "to", tx.To().Hex(), "err", err)
return fmt.Errorf("%s: %s", ErrPlatONTxDataInvalid.Error(), err.Error())
}
Expand Down
Loading

0 comments on commit 02998bf

Please sign in to comment.