resolve conflict from master

This commit is contained in:
liam.icheng.lai 2024-10-30 16:47:26 -07:00
commit 59a7eb1f9f
14 changed files with 111 additions and 42 deletions

View file

@ -1242,6 +1242,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(DocRootFlag.Name) {
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
}
if ctx.GlobalIsSet(RPCGlobalGasCapFlag.Name) {
cfg.RPCGasCap = ctx.GlobalUint64(RPCGlobalGasCapFlag.Name)
}
if ctx.GlobalIsSet(RPCGlobalTxFeeCap.Name) {
cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCap.Name)
}

View file

@ -350,13 +350,19 @@ An API exclusively for V2 consensus, designed to assist in getting rewards of th
Given the epoch number, search the epoch switch block.
*/
func (api *API) GetBlockInfoByEpochNum(epochNumber uint64) (*utils.EpochNumInfo, error) {
result, err := api.XDPoS.EngineV2.GetBlockByEpochNumber(api.chain, epochNumber)
thisEpoch, err := api.XDPoS.EngineV2.GetBlockByEpochNumber(api.chain, epochNumber)
if err != nil {
return nil, err
}
return &utils.EpochNumInfo{
EpochBlockHash: result.Hash,
EpochRound: result.Round,
EpochBlockNumber: result.Number,
}, nil
info := &utils.EpochNumInfo{
EpochBlockHash: thisEpoch.Hash,
EpochRound: thisEpoch.Round,
EpochFirstBlockNumber: thisEpoch.Number,
}
nextEpoch, err := api.XDPoS.EngineV2.GetBlockByEpochNumber(api.chain, epochNumber+1)
if err == nil {
info.EpochLastBlockNumber = new(big.Int).Sub(nextEpoch.Number, big.NewInt(1))
}
return info, nil
}

View file

@ -661,6 +661,10 @@ func (x *XDPoS_v2) VoteHandler(chain consensus.ChainReader, voteMsg *types.Vote)
3. Broadcast(Not part of consensus)
*/
func (x *XDPoS_v2) VerifyTimeoutMessage(chain consensus.ChainReader, timeoutMsg *types.Timeout) (bool, error) {
if timeoutMsg.Round < x.currentRound {
log.Debug("[VerifyTimeoutMessage] Disqualified timeout message as the proposed round does not match currentRound", "timeoutHash", timeoutMsg.Hash(), "timeoutRound", timeoutMsg.Round, "currentRound", x.currentRound)
return false, nil
}
snap, err := x.getSnapshot(chain, timeoutMsg.GapNumber, true)
if err != nil || snap == nil {
log.Error("[VerifyTimeoutMessage] Fail to get snapshot when verifying timeout message!", "messageGapNumber", timeoutMsg.GapNumber, "err", err)

View file

@ -87,6 +87,7 @@ Forensics runs in a seperate go routine as its no system critical
Link to the flow diagram: https://hashlabs.atlassian.net/wiki/spaces/HASHLABS/pages/97878029/Forensics+Diagram+flow
*/
func (f *Forensics) ProcessForensics(chain consensus.ChainReader, engine *XDPoS_v2, incomingQC types.QuorumCert) error {
return nil
log.Debug("Received a QC in forensics", "QC", incomingQC)
// Clone the values to a temporary variable
highestCommittedQCs := f.HighestCommittedQCs
@ -394,6 +395,7 @@ Forensics runs in a seperate go routine as its no system critical
Link to the flow diagram: https://hashlabs.atlassian.net/wiki/spaces/HASHLABS/pages/99516417/Vote+Equivocation+detection+specification
*/
func (f *Forensics) ProcessVoteEquivocation(chain consensus.ChainReader, engine *XDPoS_v2, incomingVote *types.Vote) error {
return nil
log.Debug("Received a vote in forensics", "vote", incomingVote)
// Clone the values to a temporary variable
highestCommittedQCs := f.HighestCommittedQCs
@ -484,6 +486,7 @@ func (f *Forensics) isVoteBlamed(chain consensus.ChainReader, highestCommittedQC
}
func (f *Forensics) DetectEquivocationInVotePool(vote *types.Vote, votePool *utils.Pool) {
return
poolKey := vote.PoolKey()
votePoolKeys := votePool.PoolObjKeysList()
signer, err := GetVoteSignerAddresses(vote)

View file

@ -74,7 +74,8 @@ type PublicApiMissedRoundsMetadata struct {
// Given an epoch number, this struct records the epoch switch block (first block in epoch) infos such as block number
type EpochNumInfo struct {
EpochBlockHash common.Hash `json:"hash"`
EpochRound types.Round `json:"round"`
EpochBlockNumber *big.Int `json:"number"`
EpochBlockHash common.Hash `json:"hash"`
EpochRound types.Round `json:"round"`
EpochFirstBlockNumber *big.Int `json:"firstBlock"`
EpochLastBlockNumber *big.Int `json:"lastBlock"`
}

View file

@ -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)

View file

@ -439,11 +439,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)

View file

@ -11,7 +11,7 @@ import (
const maxBlockDist = 7 // Maximum allowed backward distance from the chain head, 7 is just a magic number indicate very close block
//Define Boradcast Group functions
// Define Boradcast Group functions
type broadcastVoteFn func(*types.Vote)
type broadcastTimeoutFn func(*types.Timeout)
type broadcastSyncInfoFn func(*types.SyncInfo)
@ -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 {
@ -126,8 +125,8 @@ func (b *Bfter) Timeout(peer string, timeout *types.Timeout) error {
return err
}
b.broadcastCh <- timeout
if verified {
b.broadcastCh <- timeout
err = b.consensus.timeoutHandler(b.blockChainReader, timeout)
if err != nil {
if _, ok := err.(*utils.ErrIncomingMessageRoundNotEqualCurrentRound); ok {
@ -156,9 +155,9 @@ func (b *Bfter) SyncInfo(peer string, syncInfo *types.SyncInfo) error {
return err
}
b.broadcastCh <- syncInfo
// Process only if verified and qualified
if verified {
b.broadcastCh <- syncInfo
err = b.consensus.syncInfoHandler(b.blockChainReader, syncInfo)
if err != nil {
log.Error("handle BFT SyncInfo", "error", err)

View file

@ -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)
}
}

View file

@ -37,13 +37,13 @@ var (
)
const (
maxKnownTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownOrderTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownLendingTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks = 1024 // Maximum block hashes to keep in the known list (prevent DOS)
maxKnownVote = 1024 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownTimeout = 1024 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownSyncInfo = 1024 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownOrderTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownLendingTxs = 32768 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks = 1024 // Maximum block hashes to keep in the known list (prevent DOS)
maxKnownVote = 131072 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownTimeout = 131072 // Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownSyncInfo = 131072 // Maximum transactions hashes to keep in the known list (prevent DOS)
handshakeTimeout = 5 * time.Second
)

View file

@ -106,7 +106,7 @@ var Flags = []cli.Flag{
//blockprofilerateFlag,
cpuprofileFlag,
//traceFlag,
//periodicProfilingFlag,
periodicProfilingFlag,
debugDataDirFlag,
}

View file

@ -877,7 +877,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)
@ -1036,7 +1036,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)
@ -1184,25 +1184,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
}

View file

@ -48,6 +48,38 @@ var (
TimeoutPeriod: 30,
MinePeriod: 2,
},
2000: {
MaxMasternodes: 108,
SwitchRound: 2000,
CertThreshold: 0.667,
TimeoutSyncThreshold: 2,
TimeoutPeriod: 600,
MinePeriod: 2,
},
8000: {
MaxMasternodes: 108,
SwitchRound: 8000,
CertThreshold: 0.667,
TimeoutSyncThreshold: 2,
TimeoutPeriod: 60,
MinePeriod: 2,
},
220000: {
MaxMasternodes: 108,
SwitchRound: 220000,
CertThreshold: 0.667,
TimeoutSyncThreshold: 2,
TimeoutPeriod: 30,
MinePeriod: 2,
},
460000: {
MaxMasternodes: 108,
SwitchRound: 460000,
CertThreshold: 0.667,
TimeoutSyncThreshold: 2,
TimeoutPeriod: 20,
MinePeriod: 2,
},
}
TestnetV2Configs = map[uint64]*V2Config{

View file

@ -21,10 +21,10 @@ import (
)
const (
VersionMajor = 2 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 1 // Patch version component of the current release
VersionMeta = "beta1" // Version metadata to append to the version string
VersionMajor = 2 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
)
// Version holds the textual version string.