Skip to content

Commit 50ae0c9

Browse files
authored
xin-197 xin-198 fix devnet issues (ethereum#99)
* xin-197 xin-198 fix devnet issues * update log
1 parent 0317e87 commit 50ae0c9

File tree

8 files changed

+39
-48
lines changed

8 files changed

+39
-48
lines changed

consensus/XDPoS/engines/engine_v2/engine.go

+13-37
Original file line numberDiff line numberDiff line change
@@ -422,35 +422,16 @@ func (x *XDPoS_v2) CalcDifficulty(chain consensus.ChainReader, time uint64, pare
422422
}
423423

424424
func (x *XDPoS_v2) IsAuthorisedAddress(chain consensus.ChainReader, header *types.Header, address common.Address) bool {
425-
x.lock.RLock()
426-
defer x.lock.RUnlock()
427-
428-
_, round, _, err := x.getExtraFields(header)
425+
snap, err := x.GetSnapshot(chain, header)
429426
if err != nil {
430-
log.Error("[IsAuthorisedAddress] Fail to decode v2 extra data", "Hash", header.Hash().Hex(), "Extra", header.Extra, "Error", err)
427+
log.Error("[IsAuthorisedAddress] Can't get snapshot with at ", "number", header.Number, "hash", header.Hash().Hex(), "err", err)
431428
return false
432429
}
433-
blockRound := round
434-
435-
masterNodes := x.GetMasternodes(chain, header)
436-
437-
if len(masterNodes) == 0 {
438-
log.Error("[IsAuthorisedAddress] Fail to find any master nodes from current block round epoch", "Hash", header.Hash().Hex(), "Round", blockRound, "Number", header.Number)
439-
return false
440-
}
441-
442-
for index, masterNodeAddress := range masterNodes {
443-
if masterNodeAddress == address {
444-
log.Debug("[IsAuthorisedAddress] Found matching master node address", "index", index, "Address", address, "MasterNodes", masterNodes)
430+
for _, mn := range snap.NextEpochMasterNodes {
431+
if mn == address {
445432
return true
446433
}
447434
}
448-
449-
log.Warn("Not authorised address", "Address", address.Hex(), "Hash", header.Hash().Hex(), "round", round)
450-
for index, mn := range masterNodes {
451-
log.Warn("Master node list item", "mn", mn.Hex(), "index", index)
452-
}
453-
454435
return false
455436
}
456437

@@ -679,9 +660,9 @@ func (x *XDPoS_v2) ProposedBlockHandler(chain consensus.ChainReader, blockHeader
679660
return err
680661
}
681662

682-
err = x.allowedToSend(chain, blockHeader, "vote")
683-
if err != nil {
684-
return err
663+
allow := x.allowedToSend(chain, blockHeader, "vote")
664+
if !allow {
665+
return nil
685666
}
686667

687668
verified, err := x.verifyVotingRule(chain, blockInfo, quorumCert)
@@ -1013,8 +994,7 @@ func (x *XDPoS_v2) FindParentBlockToAssign(chain consensus.ChainReader) *types.B
1013994
return parent
1014995
}
1015996

1016-
func (x *XDPoS_v2) allowedToSend(chain consensus.ChainReader, blockHeader *types.Header, sendType string) error {
1017-
allowedToSend := false
997+
func (x *XDPoS_v2) allowedToSend(chain consensus.ChainReader, blockHeader *types.Header, sendType string) bool {
1018998
// Don't hold the signFn for the whole signing operation
1019999
x.signLock.RLock()
10201000
signer := x.signer
@@ -1024,18 +1004,14 @@ func (x *XDPoS_v2) allowedToSend(chain consensus.ChainReader, blockHeader *types
10241004
for i, mn := range masterNodes {
10251005
if signer == mn {
10261006
log.Debug("[allowedToSend] Yes, I'm allowed to send", "sendType", sendType, "MyAddress", signer.Hex(), "Index in master node list", i)
1027-
allowedToSend = true
1028-
break
1007+
return true
10291008
}
10301009
}
1031-
if !allowedToSend {
1032-
for _, mn := range masterNodes {
1033-
log.Debug("[allowedToSend] Master node list", "masterNodeAddress", mn.Hash())
1034-
}
1035-
log.Warn("[allowedToSend] Not in the Masternode list, not suppose to send", "sendType", sendType, "MyAddress", signer.Hex())
1036-
return fmt.Errorf("Not in the master node list, not suppose to %v", sendType)
1010+
for _, mn := range masterNodes {
1011+
log.Debug("[allowedToSend] Master node list", "masterNodeAddress", mn.Hash())
10371012
}
1038-
return nil
1013+
log.Info("[allowedToSend] Not in the Masternode list, not suppose to send message", "sendType", sendType, "MyAddress", signer.Hex())
1014+
return false
10391015
}
10401016

10411017
// Periodlly execution(Attached to engine initialisation during "new"). Used for pool cleaning etc

consensus/XDPoS/engines/engine_v2/timeout.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ func (x *XDPoS_v2) OnCountdownTimeout(time time.Time, chain interface{}) error {
208208
defer x.lock.Unlock()
209209

210210
// Check if we are within the master node list
211-
err := x.allowedToSend(chain.(consensus.ChainReader), chain.(consensus.ChainReader).CurrentHeader(), "timeout")
212-
if err != nil {
213-
return err
211+
allow := x.allowedToSend(chain.(consensus.ChainReader), chain.(consensus.ChainReader).CurrentHeader(), "timeout")
212+
if !allow {
213+
return nil
214214
}
215215

216-
err = x.sendTimeout(chain.(consensus.ChainReader))
216+
err := x.sendTimeout(chain.(consensus.ChainReader))
217217
if err != nil {
218218
log.Error("Error while sending out timeout message at time: ", time)
219219
return err

consensus/tests/engine_v2_tests/authorised_masternode_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212

1313
func TestIsAuthorisedMNForConsensusV2(t *testing.T) {
1414
// we skip test for v1 since it's hard to make a real genesis block
15-
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 900, params.TestXDPoSMockChainConfig, nil)
15+
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 901, params.TestXDPoSMockChainConfig, nil)
1616
adaptor := blockchain.Engine().(*XDPoS.XDPoS)
17-
blockNum := 901
17+
blockNum := 902
1818
blockCoinBase := "0x111000000000000000000000000000000123"
19-
currentBlock = CreateBlock(blockchain, params.TestXDPoSMockChainConfig, currentBlock, blockNum, 1, blockCoinBase, signer, signFn, nil, nil)
19+
currentBlock = CreateBlock(blockchain, params.TestXDPoSMockChainConfig, currentBlock, blockNum, 2, blockCoinBase, signer, signFn, nil, nil)
2020
err := blockchain.InsertBlock(currentBlock)
2121
assert.Nil(t, err)
2222
// As long as the address is in the master node list, they are all valid

consensus/tests/engine_v2_tests/proposed_block_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -378,5 +378,17 @@ func TestProposedBlockMessageHandlerNotGenerateVoteIfSignerNotInMNlist(t *testin
378378
}
379379

380380
err = engineV2.ProposedBlockHandler(blockchain, currentBlock.Header())
381-
assert.Equal(t, "Not in the master node list, not suppose to vote", err.Error())
381+
if err != nil {
382+
t.Fatal("Fail propose proposedBlock handler", err)
383+
}
384+
385+
// Should not receive anything from the channel
386+
select {
387+
case <-engineV2.BroadcastCh:
388+
t.Fatal("Should not trigger vote")
389+
case <-time.After(2 * time.Second):
390+
// Shoud not trigger setNewRound
391+
round, _, _, _, _, _ := engineV2.GetPropertiesFaker()
392+
assert.Equal(t, types.Round(6), round)
393+
}
382394
}

eth/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ func (s *Ethereum) StartStaking(local bool) error {
507507
if XDPoS, ok := s.engine.(*XDPoS.XDPoS); ok {
508508
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
509509
if wallet == nil || err != nil {
510-
log.Error("Etherbase account unavailable locally", "err", err)
510+
log.Error("Etherbase account unavailable locally", "err", err, "address", eb.Hex())
511511
return fmt.Errorf("signer missing: %v", err)
512512
}
513513
XDPoS.Authorize(eb, wallet.SignHash)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/btcsuite/winsvc v1.0.0 // indirect
1212
github.com/cespare/cp v1.1.1
1313
github.com/davecgh/go-spew v1.1.1
14-
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea
14+
github.com/deckarep/golang-set v1.8.0
1515
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf
1616
github.com/edsrzf/mmap-go v1.0.0
1717
github.com/elastic/gosigar v0.10.5

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
7272
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7373
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea h1:j4317fAZh7X6GqbFowYdYdI0L9bwxL07jyPZIdepyZ0=
7474
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ=
75+
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
76+
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
7577
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
7678
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
7779
github.com/docker/docker v1.4.2-0.20180625184442-8e610b2b55bf h1:sh8rkQZavChcmakYiSlqu2425CHyFXLZZnvm7PDpU8M=

miner/miner.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ package miner
1919

2020
import (
2121
"fmt"
22-
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
2322
"sync/atomic"
2423

24+
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
25+
2526
"github.com/XinFinOrg/XDPoSChain/XDCx"
2627
"github.com/XinFinOrg/XDPoSChain/accounts"
2728
"github.com/XinFinOrg/XDPoSChain/common"

0 commit comments

Comments
 (0)