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

update for move pivot #2158

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
4c4c009
Merge pull request #2049 from PlatONnetwork/feature/bump-version-to-1…
benbaley Jul 11, 2023
20dcf38
Merge pull request #123 from PlatONnetwork/feature/bump-version-to-1.4.1
niuxiaojie81 Jul 17, 2023
407bab3
snapshot disabled by default
niuxiaojie81 Jul 17, 2023
b687017
Merge pull request #2110 from niuxiaojie89/feature/bump-version-to-1.4.1
benbaley Jul 17, 2023
b386fae
Merge pull request #2111 from PlatONnetwork/feature/bump-version-to-1…
benbaley Jul 19, 2023
66a7a01
Merge pull request #142 from PlatONnetwork/feature/bump-version-to-1.5.0
niuxiaojie81 Sep 5, 2023
1cd6841
修复响应GetPrepareBlock消息的bug(wal.SendPrepareVote恢复prepareBlock时缺少签名)
niuxiaojie81 Sep 8, 2023
f72a6dc
fix bug
niuxiaojie81 Sep 8, 2023
1eb1ff5
Merge pull request #2154 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Sep 12, 2023
7a93b1b
fix downloader heighter mistake
benbaley Sep 13, 2023
3d3447a
回退trueBN算法
benbaley Sep 13, 2023
515a6e6
Merge pull request #2156 from benbaley/fix-heighter
benbaley Sep 13, 2023
187f3c7
Merge pull request #143 from PlatONnetwork/feature/bump-version-to-1.5.0
niuxiaojie81 Sep 14, 2023
d70277c
1、节点启动时不支持区块回滚
niuxiaojie81 Sep 18, 2023
80639e6
update for move pivot
cheng762 Sep 18, 2023
cee7ecf
fix sha3Uncles
cheng762 Sep 20, 2023
841615b
Merge pull request #2160 from cheng762/feature/bump-version-to-1.5.0
benbaley Sep 20, 2023
aa1bfe7
Merge pull request #2157 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Sep 20, 2023
848b198
fix wal not write when stop block chain
cheng762 Sep 20, 2023
1f76f91
BlockFetcher modifies minQueueDist restriction
benbaley Sep 22, 2023
12ec047
fix sync
benbaley Sep 22, 2023
da2931f
fix downloader heighter mistake
benbaley Sep 22, 2023
9b9c20d
fix(p2p): fix addconsensus and removeconsensus
cheng762 Sep 22, 2023
494123b
fix sha3Uncles
benbaley Sep 22, 2023
abd19d2
fix bugs
benbaley Sep 22, 2023
2b25819
Modify the judgment of the fork logic in the handshake process
benbaley Sep 22, 2023
40d3ca5
fix rs race and misdisconnect
benbaley Sep 22, 2023
2e51c0b
Merge pull request #2161 from cheng762/feature/bump-version-to-1.5.0
benbaley Sep 22, 2023
e676516
remove wal write fun
benbaley Sep 22, 2023
d7c1b2f
Merge pull request #2162 from benbaley/feature/bump-version-to-1.4.2
benbaley Sep 22, 2023
41409cd
update version to 1.4.2
benbaley Sep 22, 2023
ec5dc59
Merge pull request #2163 from benbaley/feature/bump-version-to-1.4.2
benbaley Sep 22, 2023
18cb060
Merge pull request #144 from PlatONnetwork/feature/bump-version-to-1.5.0
niuxiaojie81 Sep 22, 2023
4fdeeab
fix preCheck
niuxiaojie81 Sep 22, 2023
1d4a568
Merge pull request #2164 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Sep 22, 2023
46d761c
fix init addconsensus and removeconsensus
cheng762 Sep 22, 2023
a137268
fix init addconsensus and removeconsensus
cheng762 Sep 22, 2023
b271742
Merge pull request #2165 from cheng762/feature/bump-version-to-1.4.2
benbaley Sep 22, 2023
78fd50b
Merge pull request #2166 from cheng762/feature/bump-version-to-1.5.0
benbaley Sep 22, 2023
16e2e00
update p2p
cheng762 Sep 26, 2023
976acf3
Merge branch 'feature/bump-version-to-1.5.0' of https://github.com/Pl…
cheng762 Sep 26, 2023
8f6299e
Merge branch 'feature/bump-version-to-1.5.0' into feature/bump-versio…
cheng762 Sep 26, 2023
3f0e00c
fix bug in retry fetchPPOSStorage
cheng762 Sep 28, 2023
be0f7f3
Bump github.com/btcsuite/btcd
dependabot[bot] Oct 2, 2023
432f59f
Bump github.com/influxdata/influxdb
dependabot[bot] Oct 2, 2023
f073864
Merge pull request #2167 from PlatONnetwork/dependabot/go_modules/git…
benbaley Oct 7, 2023
f35cbdf
Merge pull request #2168 from PlatONnetwork/dependabot/go_modules/git…
benbaley Oct 7, 2023
c8e01f5
update for bls Verify Contract
cheng762 Oct 8, 2023
1268c70
fix get ppos Idle Peers
cheng762 Oct 9, 2023
87ef1a9
fix test
cheng762 Oct 9, 2023
50a9b46
Merge pull request #145 from PlatONnetwork/feature/bump-version-to-1.5.0
niuxiaojie81 Oct 10, 2023
0eec1a3
Bump golang.org/x/net from 0.9.0 to 0.17.0
dependabot[bot] Oct 11, 2023
ad48872
Remove legacy unnecessary code
niuxiaojie81 Oct 12, 2023
0675797
Merge pull request #2170 from PlatONnetwork/dependabot/go_modules/gol…
benbaley Oct 12, 2023
636b060
Merge pull request #2171 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Oct 12, 2023
e59a466
fix test
cheng762 Oct 12, 2023
dd72361
Merge pull request #2173 from cheng762/feature/bump-version-to-1.4.2
benbaley Oct 12, 2023
c3a79d7
fix ut failed
benbaley Oct 12, 2023
81bd72c
Merge pull request #2174 from benbaley/feature/bump-version-to-1.4.2
benbaley Oct 12, 2023
66d6dfc
Merge pull request #2172 from PlatONnetwork/feature/bump-version-to-1…
benbaley Oct 12, 2023
ded4f1d
Bump github.com/btcsuite/btcd
dependabot[bot] Oct 13, 2023
a925ade
Merge pull request #2175 from PlatONnetwork/dependabot/go_modules/git…
benbaley Oct 13, 2023
655fa37
fix dialPeers count
cheng762 Oct 18, 2023
11971c3
Merge pull request #2176 from cheng762/feature/bump-version-to-1.4.2
benbaley Oct 18, 2023
382e943
Merge pull request #2177 from PlatONnetwork/feature/bump-version-to-1…
benbaley Oct 18, 2023
45345f2
Merge pull request #2169 from cheng762/feature/bump-version-to-1.5.0
benbaley Oct 23, 2023
fd5abd9
go mod tidy
benbaley Oct 24, 2023
02d6046
Merge branch 'feature/bump-version-to-1.5.0' into merge1.4.2_conflict
benbaley Oct 24, 2023
5c052d3
go mod tidy
benbaley Oct 24, 2023
ab3522b
go mod tidy
benbaley Oct 24, 2023
fc3a613
Merge pull request #2178 from PlatONnetwork/merge1.4.2_conflict
benbaley Oct 24, 2023
23cf2df
update dial consensus peer
cheng762 Oct 24, 2023
a5c07df
Merge branch 'feature/bump-version-to-1.5.0' of https://github.com/Pl…
cheng762 Oct 24, 2023
bca07a3
update
cheng762 Oct 24, 2023
8e0e803
fix
cheng762 Oct 26, 2023
53b6581
fix
cheng762 Oct 26, 2023
c3c2848
Merge pull request #2180 from cheng762/feature/bump-version-to-1.5.0
benbaley Oct 26, 2023
e3637c7
校验Header时,根据不同情况同步或异步从Cbft中获取parent区块
niuxiaojie81 Oct 27, 2023
a22f9df
Merge pull request #2181 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Oct 27, 2023
df8cb5a
Merge pull request #146 from PlatONnetwork/feature/bump-version-to-1.5.0
niuxiaojie81 Oct 30, 2023
1ebc677
Increase the number of cache blocks downloaded
niuxiaojie81 Oct 30, 2023
cf2fb08
snapshot enable by default
niuxiaojie81 Oct 30, 2023
02998bf
Merge remote-tracking branch 'origin/feature/bump-version-to-1.5.0' i…
cheng762 Oct 30, 2023
d7b985f
Merge pull request #2182 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Oct 30, 2023
3f90cbc
fix test
cheng762 Oct 31, 2023
3387b37
fix dial state Remove Consensus Peer Fn
cheng762 Oct 31, 2023
0e2bd09
When platon starts, add the consensus node of the current epoch to p2…
niuxiaojie81 Oct 31, 2023
a0bbdce
Merge pull request #2185 from niuxiaojie89/feature/bump-version-to-1.5.0
benbaley Oct 31, 2023
a806b3a
Merge pull request #2184 from cheng762/feature/bump-version-to-1.5.0
benbaley Oct 31, 2023
8b282bb
fix test and improve fetch ppos
cheng762 Nov 1, 2023
7206909
fix some test and update answerGetPPOSStorageMsgQueryV2
cheng762 Nov 1, 2023
d29c0c0
Merge pull request #2186 from cheng762/feature/bump-version-to-1.5.0
benbaley Nov 1, 2023
a1724a8
Merge branch 'feature/bump-version-to-1.5.0' into feature/bump-versio…
cheng762 Nov 1, 2023
898180c
update for AddValidatorEvent
cheng762 Nov 1, 2023
bd830c6
update for AddValidatorEvent
cheng762 Nov 1, 2023
193a889
fix discover
cheng762 Nov 2, 2023
0f6d6fc
update
cheng762 Nov 2, 2023
8365bee
Merge branch 'feature/bump-version-to-1.5.0' into feature/bump-versio…
cheng762 Nov 3, 2023
b117765
update
cheng762 Nov 3, 2023
bfbd10f
fix
cheng762 Nov 3, 2023
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
2 changes: 1 addition & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (b *SimulatedBackend) Commit() {
panic(err) // This cannot happen unless the simulator is wrong, fail in that case
}
stateDB, _ := b.blockchain.State()
b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true)
b.blockchain.WriteBlockWithState(b.pendingBlock, b.pendingReceipts, nil, stateDB, true, nil)
b.rollback()
}

Expand Down
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
2 changes: 1 addition & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) ethapi.Backend
} else {
backend, err := eth.New(stack, cfg)
if err != nil {
Fatalf("Failed to register the Ethereum service: %v", err)
Fatalf("Failed to register the PlatON service: %v", err)
}
stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
return backend.APIBackend
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
62 changes: 7 additions & 55 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 @@ -287,35 +287,12 @@ func (bm *BftMock) ConsensusNodes() ([]enode.ID, error) {
return nil, nil
}

// ShouldSeal returns whether the current node is out of the block
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 {
func (bm *BftMock) ConsensusValidators() []*cbfttypes.ValidateNode {
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) {
// ShouldSeal returns whether the current node is out of the block
func (bm *BftMock) ShouldSeal(curTime time.Time) (bool, error) {
return true, nil
}

Expand All @@ -324,16 +301,6 @@ 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 +331,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
42 changes: 38 additions & 4 deletions consensus/cbft/cbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (cbft *Cbft) ReceiveMessage(msg *ctypes.MsgInfo) error {

cMsg := msg.Msg.(ctypes.ConsensusMsg)
if invalidMsg(cMsg.EpochNum(), cMsg.ViewNum()) {
cbft.log.Debug("Invalid msg", "peer", msg.PeerID, "type", reflect.TypeOf(msg.Msg), "msg", msg.Msg.String())
cbft.log.Trace("Invalid msg", "peer", msg.PeerID, "type", reflect.TypeOf(msg.Msg), "msg", msg.Msg.String())
return nil
}

Expand Down 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 @@ -1180,6 +1185,16 @@ func (cbft *Cbft) ConsensusNodes() ([]enode.ID, error) {
return cbft.validatorPool.ValidatorList(cbft.state.Epoch()), nil
}

// ConsensusNodes returns to the list of consensus nodes.
func (cbft *Cbft) ConsensusValidators() []*cbfttypes.ValidateNode {
vs := cbft.validatorPool.Validators(cbft.state.Epoch())
nodeList := make([]*cbfttypes.ValidateNode, 0)
for _, node := range vs.Nodes {
nodeList = append(nodeList, node)
}
return nodeList
}

// ShouldSeal check if we can seal block.
func (cbft *Cbft) ShouldSeal(curTime time.Time) (bool, error) {
if cbft.isLoading() || !cbft.isStart() || !cbft.running() {
Expand Down Expand Up @@ -1312,6 +1327,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
2 changes: 1 addition & 1 deletion consensus/cbft/sync_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (cbft *Cbft) prepareVoteFetchRules(id string, vote *protocols.PrepareVote)
func (cbft *Cbft) OnGetPrepareBlock(id string, msg *protocols.GetPrepareBlock) error {
if msg.Epoch == cbft.state.Epoch() && msg.ViewNumber == cbft.state.ViewNumber() {
prepareBlock := cbft.state.PrepareBlockByIndex(msg.BlockIndex)
if prepareBlock != nil {
if prepareBlock != nil && prepareBlock.Signature.NotEmpty() {
cbft.log.Debug("Send PrepareBlock", "peer", id, "prepareBlock", prepareBlock.String())
cbft.network.Send(id, prepareBlock)
}
Expand Down
7 changes: 6 additions & 1 deletion consensus/cbft/types/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.


package types

import (
"bytes"
"fmt"
"reflect"

Expand Down Expand Up @@ -48,6 +48,11 @@ func (sig *Signature) Bytes() []byte {
return target
}

func (sig *Signature) NotEmpty() bool {
var a Signature
return bytes.Compare(sig.Bytes(), a.Bytes()) != 0
}

// MarshalText returns the hex representation of a.
func (sig Signature) MarshalText() ([]byte, error) {
return hexutil.Bytes(sig[:]).MarshalText()
Expand Down
10 changes: 9 additions & 1 deletion consensus/cbft/types/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the PlatON-Go library. If not, see <http://www.gnu.org/licenses/>.


package types

import (
Expand Down Expand Up @@ -106,3 +105,12 @@ func Test_ViewChangeQC_MaxBlock(t *testing.T) {
epoch, viewNumber, blockEpoch, blockViewNumber, blockHash, blockNumber = viewChangeQC.MaxBlock()
assert.Equal(t, uint64(0), epoch)
}

func Test_Signature_NotEmpty(t *testing.T) {
var sig Signature
assert.False(t, sig.NotEmpty())
sig = Signature{byte(0), byte(0), byte(0)}
assert.False(t, sig.NotEmpty())
sig = Signature{byte(0), byte(0), byte(1)}
assert.True(t, sig.NotEmpty())
}
45 changes: 32 additions & 13 deletions consensus/cbft/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,17 @@ func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *even

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

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

removes := make([]*enode.Node, 0)
adds := make([]*enode.Node, 0)

if isValidatorBefore {
// If we are still a consensus node, that adding
// new validators as consensus peer, and removing
Expand All @@ -427,23 +438,24 @@ func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *even
// in the consensus stages. Also we are not needed
// to keep connect with old validators.
if isValidatorAfter {
for nodeID, vnode := range vp.currentValidators.Nodes {
if node, _ := vp.prevValidators.FindNodeByID(nodeID); node == nil {
eventMux.Post(cbfttypes.AddValidatorEvent{Node: enode.NewV4(vnode.PubKey, nil, 0, 0)})
log.Trace("Post AddValidatorEvent", "nodeID", nodeID.String())
for nodeID, vnode := range vp.prevValidators.Nodes {
if node, _ := vp.currentValidators.FindNodeByID(nodeID); node == nil {
removes = append(removes, enode.NewV4(vnode.PubKey, nil, 0, 0))
log.Trace("add to RemoveValidatorEvent", "nodeID", nodeID, "isValidatorAfter")
}
}

for nodeID, vnode := range vp.prevValidators.Nodes {
if node, _ := vp.currentValidators.FindNodeByID(nodeID); node == nil {
eventMux.Post(cbfttypes.RemoveValidatorEvent{Node: enode.NewV4(vnode.PubKey, nil, 0, 0)})
log.Trace("Post RemoveValidatorEvent", "nodeID", nodeID.String())
for nodeID, vnode := range vp.currentValidators.Nodes {
if node, _ := vp.prevValidators.FindNodeByID(nodeID); node == nil {
adds = append(adds, enode.NewV4(vnode.PubKey, nil, 0, 0))
log.Trace("add to AddValidatorEvent", "nodeID", nodeID)
}
}

} else {
for nodeID, vnode := range vp.prevValidators.Nodes {
eventMux.Post(cbfttypes.RemoveValidatorEvent{Node: enode.NewV4(vnode.PubKey, nil, 0, 0)})
log.Trace("Post RemoveValidatorEvent", "nodeID", nodeID.String())
removes = append(removes, enode.NewV4(vnode.PubKey, nil, 0, 0))
log.Trace("add to RemoveValidatorEvent", "nodeID", nodeID)
}
}
} else {
Expand All @@ -453,12 +465,19 @@ func (vp *ValidatorPool) Update(blockNumber uint64, epoch uint64, eventMux *even
// with other validators in the consensus stages.
if isValidatorAfter {
for nodeID, vnode := range vp.currentValidators.Nodes {
eventMux.Post(cbfttypes.AddValidatorEvent{Node: enode.NewV4(vnode.PubKey, nil, 0, 0)})
log.Trace("Post AddValidatorEvent", "nodeID", nodeID.String())
adds = append(adds, enode.NewV4(vnode.PubKey, nil, 0, 0))
log.Trace("add to AddValidatorEvent", "nodeID", nodeID)
}
}
}

if len(removes) > 0 {
eventMux.Post(cbfttypes.RemoveValidatorEvent{Nodes: removes})
log.Trace("Post RemoveValidatorEvent", "num", len(removes), "isValidatorBefore", isValidatorBefore, "isValidatorAfter", isValidatorAfter)
}
if len(adds) > 0 {
eventMux.Post(cbfttypes.AddValidatorEvent{Nodes: adds})
log.Trace("Post AddValidatorEvent", "num", len(adds), "isValidatorBefore", isValidatorBefore, "isValidatorAfter", isValidatorAfter)
}
return nil
}

Expand Down
4 changes: 3 additions & 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 Expand Up @@ -180,6 +180,8 @@ type Bft interface {
// Returns the current consensus node address list.
ConsensusNodes() ([]enode.ID, error)

ConsensusValidators() []*cbfttypes.ValidateNode

// Returns whether the current node is out of the block
ShouldSeal(curTime time.Time) (bool, error)

Expand Down
Loading