mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-29 17:57:36 +00:00
Fix getCandidateStatus API (#663)
* Fix getCandidateStatus API * sync vote message and fix test * update function name --------- Co-authored-by: Liam Lai <liam@home>
This commit is contained in:
parent
861c7102a2
commit
eb6d53adf6
5 changed files with 38 additions and 18 deletions
|
|
@ -17,6 +17,8 @@ import (
|
|||
)
|
||||
|
||||
func TestProcessQcShallSetForensicsCommittedQc(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
|
||||
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
|
||||
|
||||
|
|
@ -92,6 +94,8 @@ func TestProcessQcShallSetForensicsCommittedQc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSetCommittedQCsInOrder(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
blockchain, _, currentBlock, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
|
||||
forensics := blockchain.Engine().(*XDPoS.XDPoS).EngineV2.GetForensicsFaker()
|
||||
|
||||
|
|
@ -118,6 +122,8 @@ func TestSetCommittedQCsInOrder(t *testing.T) {
|
|||
|
||||
// Happty path
|
||||
func TestForensicsMonitoring(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
blockchain, _, currentBlock, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 915, params.TestXDPoSMockChainConfig, nil)
|
||||
forensics := blockchain.Engine().(*XDPoS.XDPoS).EngineV2.GetForensicsFaker()
|
||||
var decodedCurrentblockExtraField types.ExtraFields_v2
|
||||
|
|
@ -140,6 +146,7 @@ func TestForensicsMonitoring(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestForensicsMonitoringNotOnSameChainButHaveSameRoundQC(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
var numOfForks = new(int)
|
||||
*numOfForks = 10
|
||||
var forkRoundDifference = new(int)
|
||||
|
|
@ -199,6 +206,8 @@ func TestForensicsMonitoringNotOnSameChainButHaveSameRoundQC(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestForensicsMonitoringNotOnSameChainDoNotHaveSameRoundQC(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
var numOfForks = new(int)
|
||||
*numOfForks = 10
|
||||
var forkRoundDifference = new(int)
|
||||
|
|
@ -260,6 +269,8 @@ func TestForensicsMonitoringNotOnSameChainDoNotHaveSameRoundQC(t *testing.T) {
|
|||
|
||||
// "prone to attack" test where the "across epoch" field is true
|
||||
func TestForensicsAcrossEpoch(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
var numOfForks = new(int)
|
||||
*numOfForks = 10
|
||||
var forkRoundDifference = new(int)
|
||||
|
|
@ -322,6 +333,8 @@ func TestForensicsAcrossEpoch(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVoteEquivocationSameRound(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
var numOfForks = new(int)
|
||||
*numOfForks = 1
|
||||
blockchain, _, currentBlock, signer, signFn, currentForkBlock := PrepareXDCTestBlockChainForV2Engine(t, 901, params.TestXDPoSMockChainConfig, &ForkedBlockOptions{numOfForkedBlocks: numOfForks})
|
||||
|
|
@ -388,6 +401,8 @@ func TestVoteEquivocationSameRound(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVoteEquivocationDifferentRound(t *testing.T) {
|
||||
t.Skip("Skipping this test for now as we disable forensics")
|
||||
|
||||
var numOfForks = new(int)
|
||||
*numOfForks = 10
|
||||
var forkRoundDifference = new(int)
|
||||
|
|
|
|||
|
|
@ -427,11 +427,11 @@ func (b *EthApiBackend) GetVotersRewards(masternodeAddr common.Address) map[comm
|
|||
// calculate for 2 epochs ago
|
||||
currentCheckpointNumber, _, err := engine.GetCurrentEpochSwitchBlock(chain, block.Number())
|
||||
if err != nil {
|
||||
log.Error("[GetVotersRewards] Fail to get GetCurrentEpochSwitchBlock for current checkpoint block", "block", block)
|
||||
log.Error("[GetVotersRewards] Fail to get GetCurrentEpochSwitchBlock for current checkpoint block", "block", block.Number(), "err", err)
|
||||
}
|
||||
lastCheckpointNumber, _, err := engine.GetCurrentEpochSwitchBlock(chain, big.NewInt(int64(currentCheckpointNumber-1)))
|
||||
if err != nil {
|
||||
log.Error("[GetVotersRewards] Fail to get GetCurrentEpochSwitchBlock for last checkpoint block", "block", block)
|
||||
log.Error("[GetVotersRewards] Fail to get GetCurrentEpochSwitchBlock for last checkpoint block", "block", block.Number(), "err", err)
|
||||
}
|
||||
|
||||
lastCheckpointBlock := chain.GetBlockByNumber(lastCheckpointNumber)
|
||||
|
|
|
|||
|
|
@ -93,9 +93,8 @@ func (b *Bfter) Vote(peer string, vote *types.Vote) error {
|
|||
return err
|
||||
}
|
||||
|
||||
b.broadcastCh <- vote
|
||||
|
||||
if verified {
|
||||
b.broadcastCh <- vote
|
||||
err = b.consensus.voteHandler(b.blockChainReader, vote)
|
||||
if err != nil {
|
||||
if _, ok := err.(*utils.ErrIncomingMessageRoundTooFarFromCurrentRound); ok {
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ func TestBoardcastButNotProcessDisqualifiedVotes(t *testing.T) {
|
|||
tester.bfter.Vote(peerID, &vote)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
if int(handlerCounter) != targetVotes || int(broadcastCounter) != 1 {
|
||||
if int(handlerCounter) != targetVotes || int(broadcastCounter) != 0 {
|
||||
t.Fatalf("count mismatch: have %v on handler, %v on broadcast, want %v", handlerCounter, broadcastCounter, targetVotes)
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +171,7 @@ func TestBoardcastButNotProcessDisqualifiedTimeout(t *testing.T) {
|
|||
tester.bfter.Timeout(peerID, &timeout)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
if int(handlerCounter) != targetTimeout || int(broadcastCounter) != 1 {
|
||||
if int(handlerCounter) != targetTimeout || int(broadcastCounter) != 0 {
|
||||
t.Fatalf("count mismatch: have %v on handler, %v on broadcast, want %v", handlerCounter, broadcastCounter, targetTimeout)
|
||||
}
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ func TestBoardcastButNotProcessDisqualifiedSyncInfo(t *testing.T) {
|
|||
tester.bfter.SyncInfo(peerID, &syncInfo)
|
||||
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
if int(handlerCounter) != targetSyncInfo || int(broadcastCounter) != 1 {
|
||||
if int(handlerCounter) != targetSyncInfo || int(broadcastCounter) != 0 {
|
||||
t.Fatalf("count mismatch: have %v on handler, %v on broadcast, want %v", handlerCounter, broadcastCounter, targetSyncInfo)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -869,7 +869,7 @@ func (s *PublicBlockChainAPI) GetCandidateStatus(ctx context.Context, coinbaseAd
|
|||
epochConfig := s.b.ChainConfig().XDPoS.Epoch
|
||||
|
||||
// checkpoint block
|
||||
checkpointNumber, epochNumber = s.GetPreviousCheckpointFromEpoch(ctx, epoch)
|
||||
checkpointNumber, epochNumber = s.GetCheckpointFromEpoch(ctx, epoch)
|
||||
result[fieldEpoch] = epochNumber.Int64()
|
||||
|
||||
block, err = s.b.BlockByNumber(ctx, checkpointNumber)
|
||||
|
|
@ -1024,7 +1024,7 @@ func (s *PublicBlockChainAPI) GetCandidates(ctx context.Context, epoch rpc.Epoch
|
|||
}
|
||||
epochConfig := s.b.ChainConfig().XDPoS.Epoch
|
||||
|
||||
checkpointNumber, epochNumber = s.GetPreviousCheckpointFromEpoch(ctx, epoch)
|
||||
checkpointNumber, epochNumber = s.GetCheckpointFromEpoch(ctx, epoch)
|
||||
result[fieldEpoch] = epochNumber.Int64()
|
||||
|
||||
block, err = s.b.BlockByNumber(ctx, checkpointNumber)
|
||||
|
|
@ -1168,25 +1168,31 @@ func (s *PublicBlockChainAPI) GetCandidates(ctx context.Context, epoch rpc.Epoch
|
|||
return result, nil
|
||||
}
|
||||
|
||||
// GetPreviousCheckpointFromEpoch returns header of the previous checkpoint
|
||||
func (s *PublicBlockChainAPI) GetPreviousCheckpointFromEpoch(ctx context.Context, epochNum rpc.EpochNumber) (rpc.BlockNumber, rpc.EpochNumber) {
|
||||
// GetCheckpointFromEpoch returns header of the previous checkpoint
|
||||
func (s *PublicBlockChainAPI) GetCheckpointFromEpoch(ctx context.Context, epochNum rpc.EpochNumber) (rpc.BlockNumber, rpc.EpochNumber) {
|
||||
var checkpointNumber uint64
|
||||
epoch := s.b.ChainConfig().XDPoS.Epoch
|
||||
|
||||
if epochNum == rpc.LatestEpochNumber {
|
||||
blockNumer := s.b.CurrentBlock().Number().Uint64()
|
||||
diff := blockNumer % epoch
|
||||
// checkpoint number
|
||||
checkpointNumber = blockNumer - diff
|
||||
epochNum = rpc.EpochNumber(checkpointNumber / epoch)
|
||||
if diff > 0 {
|
||||
epochNum += 1
|
||||
blockNumer := s.b.CurrentBlock().Number()
|
||||
if engine, ok := s.b.GetEngine().(*XDPoS.XDPoS); ok {
|
||||
var err error
|
||||
var currentEpoch uint64
|
||||
checkpointNumber, currentEpoch, err = engine.GetCurrentEpochSwitchBlock(s.chainReader, blockNumer)
|
||||
if err != nil {
|
||||
log.Error("[GetCheckpointFromEpoch] Fail to get GetCurrentEpochSwitchBlock for current checkpoint block", "block", blockNumer, "err", err)
|
||||
return 0, epochNum
|
||||
}
|
||||
|
||||
epochNum = rpc.EpochNumber(currentEpoch)
|
||||
}
|
||||
} else if epochNum < 2 {
|
||||
checkpointNumber = 0
|
||||
} else {
|
||||
// TODO this checkpointNumber needs to be recalculated for v2 blocks
|
||||
checkpointNumber = epoch * (uint64(epochNum) - 1)
|
||||
}
|
||||
|
||||
return rpc.BlockNumber(checkpointNumber), epochNum
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue