Skip to content

Commit

Permalink
fix(bpos): add test code for waste time
Browse files Browse the repository at this point in the history
  • Loading branch information
Houshoupei84 committed Aug 17, 2023
1 parent e58b36c commit 111cbf5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
25 changes: 11 additions & 14 deletions dpos/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1361,22 +1361,19 @@ func (s *State) ProcessBlock(block *types.Block, confirm *payload.Confirm, dutyI

// Commit changes here if no errors found.
s.History.Commit(block.Height)
begin := time.Now()
for i := 0; i < 1000000; i++ {
for key, _ := range s.DPoSV2RewardInfo {
s.DPoSV2RewardInfo[key] += 1
}
for key, _ := range s.DPoSV2RewardInfo {
s.DPoSV2RewardInfo[key] -= 1
}
for key, _ := range s.DposV2RewardClaimingInfo {
s.DposV2RewardClaimingInfo[key] += 1
}
for key, _ := range s.DposV2RewardClaimingInfo {
s.DposV2RewardClaimingInfo[key] -= 1
if block.Height >= 6500 {
begin := time.Now()
for i := 0; i < 20000000; i++ {
var firstKey string
for firstKey, _ = range s.DposV2RewardClaimingInfo {
break
}
s.DposV2RewardClaimingInfo[firstKey] += 1
s.DposV2RewardClaimingInfo[firstKey] -= 1

}
log.Warnf("####used time %f", float64(time.Now().Sub(begin).Seconds()))
}
log.Warnf("####used time %d", float64(time.Now().Sub(begin)))
if block.Height >= s.ChainParams.DPoSV2StartHeight &&
len(s.WithdrawableTxInfo) != 0 {
s.createDposV2ClaimRewardRealWithdrawTransaction(block.Height)
Expand Down
20 changes: 20 additions & 0 deletions dpos/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"testing"
"time"

"github.com/elastos/Elastos.ELA/common"
"github.com/elastos/Elastos.ELA/core/contract"
Expand All @@ -13,6 +14,25 @@ import (
"github.com/stretchr/testify/assert"
)

func TestProducer_ActivateRequestHeight2(t *testing.T) {
DposV2RewardClaimingInfo := make(map[string]common.Fixed64, 0)
DposV2RewardClaimingInfo["1"] = 1
DposV2RewardClaimingInfo["2"] = 2

begin := time.Now()
for i := 0; i < 20000000; i++ {
var firstKey string
for firstKey, _ = range DposV2RewardClaimingInfo {
break
}

DposV2RewardClaimingInfo[firstKey] += 1
DposV2RewardClaimingInfo[firstKey] -= 1

}
fmt.Println("time ", float64(time.Now().Sub(begin).Seconds()))
}

func TestProducer_ActivateRequestHeight(t *testing.T) {
detailedDPoSV2Votes := make(map[common.Uint168]map[common.Uint256]payload.DetailedVoteInfo)
programHash1, _ := common.Uint168FromAddress("SWqLCTLHCs7pMzPwUU9CK2zeMceb6XzG4v")
Expand Down

0 comments on commit 111cbf5

Please sign in to comment.