Skip to content

Commit b4a1478

Browse files
authored
Add fixedSize option to ABLA config and modify net params (gcash#553)
* Add fixedSize option to ABLA config * Modify testnet params * Fix linter issue * Modify TestNet4Params
1 parent 70e626f commit b4a1478

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

blockchain/abla_ewma_elastic_buffer.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,26 @@ type ABLAConfig struct {
9494
epsilonMax uint64
9595
// Maximum elastic buffer size value
9696
betaMax uint64
97+
// If true, it means we have a flat block size limit so epsilonMax and betaMax must equal epsilon0 and beta0
98+
fixedSize bool
9799
}
98100

99101
// Set epsilonMax and betaMax such that algo's internal arithmetic ops can't overflow UINT64_MAX
100102
func (config *ABLAConfig) SetMax() {
101-
maxSafeBlocksizeLimit := UINT64_MAX / config.zetaXB7 * B7
103+
if !config.fixedSize {
104+
maxSafeBlocksizeLimit := UINT64_MAX / config.zetaXB7 * B7
102105

103-
// elastic_buffer_ratio_max = (delta * gamma / theta * (zeta - 1)) / (gamma / theta * (zeta - 1) + 1)
104-
maxElasticBufferRatioNumerator := config.delta * ((config.zetaXB7 - B7) * config.thetaReciprocal / config.gammaReciprocal)
105-
maxElasticBufferRatioDenominator := (config.zetaXB7-B7)*config.thetaReciprocal/config.gammaReciprocal + B7
106+
// elastic_buffer_ratio_max = (delta * gamma / theta * (zeta - 1)) / (gamma / theta * (zeta - 1) + 1)
107+
maxElasticBufferRatioNumerator := config.delta * ((config.zetaXB7 - B7) * config.thetaReciprocal / config.gammaReciprocal)
108+
maxElasticBufferRatioDenominator := (config.zetaXB7-B7)*config.thetaReciprocal/config.gammaReciprocal + B7
106109

107-
config.epsilonMax = maxSafeBlocksizeLimit / (maxElasticBufferRatioNumerator + maxElasticBufferRatioDenominator) * maxElasticBufferRatioDenominator
108-
config.betaMax = maxSafeBlocksizeLimit - config.epsilonMax
110+
config.epsilonMax = maxSafeBlocksizeLimit / (maxElasticBufferRatioNumerator + maxElasticBufferRatioDenominator) * maxElasticBufferRatioDenominator
111+
config.betaMax = maxSafeBlocksizeLimit - config.epsilonMax
112+
} else {
113+
// we have a flat limit
114+
config.epsilonMax = config.epsilon0
115+
config.betaMax = config.beta0
116+
}
109117

110118
fmt.Fprintf(os.Stderr, "[INFO] Auto-configured epsilonMax: %d, betaMax: %d\n", config.epsilonMax, config.betaMax)
111119
}

blockchain/abla_ewma_elastic_buffer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func TestABLA(t *testing.T) {
113113
zetaXB7: testData.ABLAConfig.Zeta,
114114
thetaReciprocal: testData.ABLAConfig.ThetaReciprocal,
115115
delta: testData.ABLAConfig.Delta,
116+
fixedSize: false,
116117
}
117118
ablaConfig.SetMax()
118119

blockchain/chain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,7 @@ func New(config *Config) (*BlockChain, error) {
22962296
zetaXB7: params.ABLAConfig.ZetaXB7,
22972297
thetaReciprocal: params.ABLAConfig.ThetaReciprocal,
22982298
delta: params.ABLAConfig.Delta,
2299+
fixedSize: params.ABLAConfig.FixedSize,
22992300
}
23002301
if uint64(config.ExcessiveBlockSize) > ablaConfig.beta0 && ablaConfig.beta0 > 0 {
23012302
ablaConfig.epsilon0 = uint64(config.ExcessiveBlockSize) - ablaConfig.beta0

chaincfg/params.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ type ABLAConstants struct {
109109
ZetaXB7 uint64
110110
ThetaReciprocal uint64
111111
Delta uint64
112+
FixedSize bool
112113
}
113114

114115
// Params defines a Bitcoin network by its parameters. These parameters may be
@@ -315,6 +316,7 @@ var MainNetParams = Params{
315316
ZetaXB7: 192,
316317
ThetaReciprocal: 37938,
317318
Delta: 10,
319+
FixedSize: false,
318320
},
319321

320322
CoinbaseMaturity: 100,
@@ -495,6 +497,7 @@ var RegressionNetParams = Params{
495497
ZetaXB7: 192,
496498
ThetaReciprocal: 37938,
497499
Delta: 10,
500+
FixedSize: true,
498501
},
499502

500503
SubsidyReductionInterval: 150,
@@ -589,6 +592,20 @@ var TestNet3Params = Params{
589592

590593
CosmicInflationActivationTime: 1652616000,
591594

595+
Upgrade9ForkHeight: 1552787,
596+
ABLAForkHeight: 1605520,
597+
598+
ABLAConfig: ABLAConstants{
599+
Epsilon0: 16000000,
600+
Beta0: 16000000,
601+
N0: 845890,
602+
GammaReciprocal: 37938,
603+
ZetaXB7: 192,
604+
ThetaReciprocal: 37938,
605+
Delta: 10,
606+
FixedSize: true,
607+
},
608+
592609
CoinbaseMaturity: 100,
593610
SubsidyReductionInterval: 210000,
594611
TargetTimespan: time.Hour * 24 * 14, // 14 days
@@ -702,6 +719,7 @@ var ChipNetParams = Params{
702719
ZetaXB7: 192,
703720
ThetaReciprocal: 37938,
704721
Delta: 10,
722+
FixedSize: false,
705723
},
706724

707725
CosmicInflationActivationTime: 1637694000,
@@ -797,6 +815,20 @@ var TestNet4Params = Params{
797815

798816
CosmicInflationActivationTime: 1637694000,
799817

818+
Upgrade9ForkHeight: 148043,
819+
ABLAForkHeight: 200740,
820+
821+
ABLAConfig: ABLAConstants{
822+
Epsilon0: 1000000,
823+
Beta0: 1000000,
824+
N0: 845890,
825+
GammaReciprocal: 37938,
826+
ZetaXB7: 192,
827+
ThetaReciprocal: 37938,
828+
Delta: 10,
829+
FixedSize: true,
830+
},
831+
800832
CoinbaseMaturity: 100,
801833
SubsidyReductionInterval: 210000,
802834
TargetTimespan: time.Hour * 24 * 14, // 14 days
@@ -906,6 +938,7 @@ var SimNetParams = Params{
906938
ZetaXB7: 192,
907939
ThetaReciprocal: 37938,
908940
Delta: 10,
941+
FixedSize: true,
909942
},
910943

911944
// Checkpoints ordered from oldest to newest.

0 commit comments

Comments
 (0)