Skip to content

Commit 7fcf552

Browse files
committed
modify tx size limit - upgrade9
1 parent 6c347a6 commit 7fcf552

6 files changed

Lines changed: 44 additions & 10 deletions

File tree

blockchain/process.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const (
3333
// set.
3434
BFMagneticAnomaly
3535

36+
// BFUpgrade9 signals that the upgrade9 hardfork is
37+
// active and the block should be validated according the new rule
38+
// set.
39+
BFUpgrade9
40+
3641
// BFNoDupBlockCheck signals if the block should skip existence
3742
// checks.
3843
BFNoDupBlockCheck
@@ -195,6 +200,10 @@ func (b *BlockChain) ProcessBlock(block *bchutil.Block, flags BehaviorFlags) (bo
195200
flags |= BFMagneticAnomaly
196201
}
197202

203+
if block.Height() > b.chainParams.Upgrade9ForkHeight {
204+
flags |= BFUpgrade9
205+
}
206+
198207
// Perform preliminary sanity checks on the block and its transactions.
199208
err := checkBlockSanity(block, b.chainParams.PowLimit, b.timeSource, flags)
200209
if err != nil {

blockchain/validate.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ const (
5353
// after the UAHF hard fork
5454
MaxTransactionSize = oneMegabyte
5555

56-
// MinTransactionSize is the minimum transaction size allowed on the
56+
// MagneticAnomalyMinTransactionSize is the minimum transaction size allowed on the
5757
// network after the magneticanomaly hardfork
58+
MagneticAnomalyMinTransactionSize = 100
59+
60+
// MinTransactionSize is the minimum transaction size allowed on the
61+
// network after the upgrade9 hardfork
5862
MinTransactionSize = 65
5963

6064
// BlockMaxBytesMaxSigChecksRatio is the ratio between the maximum allowable
@@ -235,7 +239,7 @@ func CalcBlockSubsidy(height int32, chainParams *chaincfg.Params) int64 {
235239

236240
// CheckTransactionSanity performs some preliminary checks on a transaction to
237241
// ensure it is sane. These checks are context free.
238-
func CheckTransactionSanity(tx *bchutil.Tx, magneticAnomalyActive bool, scriptFlags txscript.ScriptFlags) error {
242+
func CheckTransactionSanity(tx *bchutil.Tx, magneticAnomalyActive bool, upgrade9Active bool, scriptFlags txscript.ScriptFlags) error {
239243
// A transaction must have at least one input.
240244
msgTx := tx.MsgTx()
241245
if len(msgTx.TxIn) == 0 {
@@ -255,9 +259,14 @@ func CheckTransactionSanity(tx *bchutil.Tx, magneticAnomalyActive bool, scriptFl
255259
"%d, max %d", serializedTxSize, MaxTransactionSize)
256260
return ruleError(ErrTxTooBig, str)
257261
}
258-
if magneticAnomalyActive && serializedTxSize < MinTransactionSize {
262+
263+
if magneticAnomalyActive && serializedTxSize < MagneticAnomalyMinTransactionSize {
264+
minTxSize := MagneticAnomalyMinTransactionSize
265+
if upgrade9Active {
266+
minTxSize = MinTransactionSize
267+
}
259268
str := fmt.Sprintf("serialized transaction is too small - got "+
260-
"%d, min %d", serializedTxSize, MinTransactionSize)
269+
"%d, min %d", serializedTxSize, minTxSize)
261270
return ruleError(ErrTxTooSmall, str)
262271
}
263272

@@ -457,6 +466,8 @@ func checkBlockSanity(block *bchutil.Block, powLimit *big.Int, timeSource Median
457466

458467
magneticAnomaly := flags.HasFlag(BFMagneticAnomaly)
459468

469+
upgrade9 := flags.HasFlag(BFUpgrade9)
470+
460471
// TODO: This is not a full set of ScriptFlags and only
461472
// covers the Nov 2018 fork.
462473
var scriptFlags txscript.ScriptFlags
@@ -476,7 +487,7 @@ func checkBlockSanity(block *bchutil.Block, powLimit *big.Int, timeSource Median
476487
return ruleError(ErrInvalidTxOrder, "transactions are not in lexicographical order")
477488
}
478489
lastTxid = tx.Hash()
479-
err := CheckTransactionSanity(tx, magneticAnomaly, scriptFlags)
490+
err := CheckTransactionSanity(tx, magneticAnomaly, upgrade9, scriptFlags)
480491
if err != nil {
481492
return err
482493
}
@@ -516,12 +527,15 @@ func checkBlockSanity(block *bchutil.Block, powLimit *big.Int, timeSource Median
516527

517528
// CheckBlockSanity performs some preliminary checks on a block to ensure it is
518529
// sane before continuing with block processing. These checks are context free.
519-
func CheckBlockSanity(block *bchutil.Block, powLimit *big.Int, timeSource MedianTimeSource, magneticAnomalyActive bool) error {
530+
func CheckBlockSanity(block *bchutil.Block, powLimit *big.Int, timeSource MedianTimeSource, magneticAnomalyActive bool, upgrade9Active bool) error {
520531
behaviorFlags := BFNone
521532

522533
if magneticAnomalyActive {
523534
behaviorFlags |= BFMagneticAnomaly
524535
}
536+
if upgrade9Active {
537+
behaviorFlags |= BFUpgrade9
538+
}
525539

526540
return checkBlockSanity(block, powLimit, timeSource, behaviorFlags)
527541
}

blockchain/validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func TestCheckBlockSanity(t *testing.T) {
211211
powLimit := chaincfg.MainNetParams.PowLimit
212212
block := bchutil.NewBlock(&Block100000)
213213
timeSource := NewMedianTime()
214-
err := CheckBlockSanity(block, powLimit, timeSource, false)
214+
err := CheckBlockSanity(block, powLimit, timeSource, false, false)
215215
if err != nil {
216216
t.Errorf("CheckBlockSanity: %v", err)
217217
}
@@ -220,7 +220,7 @@ func TestCheckBlockSanity(t *testing.T) {
220220
// second fails.
221221
timestamp := block.MsgBlock().Header.Timestamp
222222
block.MsgBlock().Header.Timestamp = timestamp.Add(time.Nanosecond)
223-
err = CheckBlockSanity(block, powLimit, timeSource, true)
223+
err = CheckBlockSanity(block, powLimit, timeSource, true, false)
224224
if err == nil {
225225
t.Errorf("CheckBlockSanity: error is nil when it shouldn't be")
226226
}

chaincfg/params.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ type Params struct {
153153
PhononForkHeight int32 // May 15, 2020 hardfork
154154
AxionActivationHeight int32 // Nov 15, 2020 hardfork
155155
CosmicInflationActivationTime uint64 // May 15, 2022 hardfork
156+
Upgrade9ForkHeight int32 // May 15 2023 hardfork
156157

157158
// CoinbaseMaturity is the number of blocks required before newly mined
158159
// coins (coinbase transactions) can be spent.
@@ -288,6 +289,8 @@ var MainNetParams = Params{
288289

289290
CosmicInflationActivationTime: 1652616000,
290291

292+
Upgrade9ForkHeight: 792772, // 000000000000000002B678C471841C3E404EC7AE9CA9C32026FE27EB6E3A1ED1
293+
291294
CoinbaseMaturity: 100,
292295
SubsidyReductionInterval: 210000,
293296
TargetTimespan: time.Hour * 24 * 14, // 14 days

mempool/mempool.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,10 @@ func (mp *TxPool) maybeAcceptTransaction(tx *bchutil.Tx, isNew, rateLimit, rejec
740740
if nextBlockHeight > mp.cfg.ChainParams.MagneticAnonomalyForkHeight {
741741
magneticAnomalyActive = true
742742
}
743+
upgrade9Active := false
744+
if nextBlockHeight > mp.cfg.ChainParams.Upgrade9ForkHeight {
745+
upgrade9Active = true
746+
}
743747

744748
scriptFlags := txscript.StandardVerifyFlags
745749
if !mp.cfg.Policy.LimitSigChecks {
@@ -749,7 +753,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *bchutil.Tx, isNew, rateLimit, rejec
749753
// Perform preliminary sanity checks on the transaction. This makes
750754
// use of blockchain which contains the invariant rules for what
751755
// transactions are allowed into blocks.
752-
err := blockchain.CheckTransactionSanity(tx, magneticAnomalyActive, scriptFlags)
756+
err := blockchain.CheckTransactionSanity(tx, magneticAnomalyActive, upgrade9Active, scriptFlags)
753757
if err != nil {
754758
if cerr, ok := err.(blockchain.RuleError); ok {
755759
return nil, nil, chainRuleError(cerr)

rpcserver.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3841,18 +3841,22 @@ func verifyChain(s *rpcServer, level, depth int32) error {
38413841
}
38423842

38433843
magneticAnomalyActive := false
3844+
upgrade9Active := false
38443845

38453846
prevHeight := height - 1
38463847
if prevHeight > 0 {
38473848
if height > s.cfg.ChainParams.MagneticAnonomalyForkHeight {
38483849
magneticAnomalyActive = true
38493850
}
3851+
if height > s.cfg.ChainParams.Upgrade9ForkHeight {
3852+
upgrade9Active = true
3853+
}
38503854
}
38513855

38523856
// Level 1 does basic chain sanity checks.
38533857
if level > 0 {
38543858
err := blockchain.CheckBlockSanity(block,
3855-
s.cfg.ChainParams.PowLimit, s.cfg.TimeSource, magneticAnomalyActive)
3859+
s.cfg.ChainParams.PowLimit, s.cfg.TimeSource, magneticAnomalyActive, upgrade9Active)
38563860
if err != nil {
38573861
rpcsLog.Errorf("Verify is unable to validate "+
38583862
"block at hash %v height %d: %v",

0 commit comments

Comments
 (0)