• R/O
  • HTTP
  • SSH
  • HTTPS

bytom: Commit

Official Go implementation of the Bytom protocol


Commit MetaInfo

Révision90d7fd990567117a84d14572dbeefa5f44f0d9c0 (tree)
l'heure2021-08-24 15:44:55
Auteurshenao78 <shenao.78@163....>
Commitershenao78

Message de Log

dynamic_vote_pending_num

Change Summary

Modification

--- a/consensus/general.go
+++ b/consensus/general.go
@@ -3,6 +3,7 @@ package consensus
33 import (
44 "encoding/binary"
55 "fmt"
6+ "math"
67 "strings"
78
89 log "github.com/sirupsen/logrus"
@@ -37,6 +38,7 @@ const (
3738 BCRPRequiredBTMAmount = uint64(100000000)
3839
3940 BTMAlias = "BTM"
41+ defaultVotePendingNum = 302400
4042 )
4143
4244 type CasperConfig struct {
@@ -53,11 +55,17 @@ type CasperConfig struct {
5355 MinValidatorVoteNum uint64
5456
5557 // VotePendingBlockNumber is the locked block number of vote utxo
56- VotePendingBlockNumber uint64
58+ VotePendingBlockNums []VotePendingBlockNum
5759
5860 FederationXpubs []chainkd.XPub
5961 }
6062
63+type VotePendingBlockNum struct {
64+ BeginBlock uint64
65+ EndBlock uint64
66+ Num uint64
67+}
68+
6169 // BTMAssetID is BTM's asset id, the soul asset of Bytom
6270 var BTMAssetID = &bc.AssetID{
6371 V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}),
@@ -119,7 +127,10 @@ var MainNetParams = Params{
119127 MaxTimeOffsetMs: 3000,
120128 BlocksOfEpoch: 100,
121129 MinValidatorVoteNum: 1e14,
122- VotePendingBlockNumber: 14400,
130+ VotePendingBlockNums: []VotePendingBlockNum{
131+ {BeginBlock: 0, EndBlock: 432000, Num: 14400},
132+ {BeginBlock: 432000, EndBlock: math.MaxUint64, Num: defaultVotePendingNum},
133+ },
123134 FederationXpubs: []chainkd.XPub{
124135 xpub("f9003633ccbd8cc37e034f4dbe70d9fae980d437948d8cb908d0cab7909780d74a324b4decb5dfcd43fbc6b896ac066b7e02c733a1537360e933278a101a850c"),
125136 xpub("d301fee5d4ba7eb5b9d41ca13ec56c19daceb5f6b752d91d49777fd1fc7c45891e5773cafb3b6d6ab764ef2794e8ba953c8bdb9dc77a3af51e979f96885f96b2"),
@@ -140,7 +151,7 @@ var TestNetParams = Params{
140151 MaxTimeOffsetMs: 3000,
141152 BlocksOfEpoch: 100,
142153 MinValidatorVoteNum: 1e8,
143- VotePendingBlockNumber: 10,
154+ VotePendingBlockNums: []VotePendingBlockNum{{BeginBlock: 0, EndBlock: math.MaxUint64, Num: 10}},
144155 FederationXpubs: []chainkd.XPub{
145156 xpub("7732fac62320799ff5e4eec1dc4ba7b07dc0e5a647850bf0bc34cb9aca195a05a1118b57d377947d7936156c831c87b700ed945a82cae63aff14905beb39d001"),
146157 xpub("08543fef8c3ca27483954f80eee6d461c307b6aa564aafaf235a4bd2740debbc71b14af78715c94cbc1d16fa84da97a3eabc5b21f003ab49882e4af7f9f00bbd"),
@@ -159,11 +170,20 @@ var SoloNetParams = Params{
159170 MaxTimeOffsetMs: 24000,
160171 BlocksOfEpoch: 100,
161172 MinValidatorVoteNum: 1e8,
162- VotePendingBlockNumber: 10,
173+ VotePendingBlockNums: []VotePendingBlockNum{{BeginBlock: 0, EndBlock: math.MaxUint64, Num: 10}},
163174 FederationXpubs: []chainkd.XPub{},
164175 },
165176 }
166177
178+func VotePendingBlockNums(height uint64) uint64 {
179+ for _, pendingNum := range ActiveNetParams.VotePendingBlockNums {
180+ if height >= pendingNum.BeginBlock && height < pendingNum.EndBlock {
181+ return pendingNum.Num
182+ }
183+ }
184+ return defaultVotePendingNum
185+}
186+
167187 // InitActiveNetParams load the config by chain ID
168188 func InitActiveNetParams(chainID string) error {
169189 var exist bool
--- a/protocol/state/utxo_view.go
+++ b/protocol/state/utxo_view.go
@@ -42,7 +42,7 @@ func (view *UtxoViewpoint) applySpendUtxo(block *bc.Block, tx *bc.Tx) error {
4242 return errors.New("coinbase utxo is not ready for use")
4343 }
4444 case storage.VoteUTXOType:
45- if entry.BlockHeight + consensus.ActiveNetParams.VotePendingBlockNumber > block.Height {
45+ if entry.BlockHeight + consensus.VotePendingBlockNums(block.Height) > block.Height {
4646 return errors.New("Coin is within the voting lock time")
4747 }
4848 }
--- a/wallet/utxo.go
+++ b/wallet/utxo.go
@@ -230,7 +230,7 @@ func txOutToUtxos(tx *types.Tx, blockHeight uint64) []*account.UTXO {
230230 }
231231
232232 case *bc.VoteOutput:
233- voteValidHeight := blockHeight + consensus.ActiveNetParams.VotePendingBlockNumber
233+ voteValidHeight := blockHeight + consensus.VotePendingBlockNums(blockHeight)
234234 if validHeight < voteValidHeight {
235235 validHeight = voteValidHeight
236236 }
Afficher sur ancien navigateur de dépôt.