@@ -1013,6 +1013,56 @@ func (p *BlobPool) reinject(addr common.Address, txhash common.Hash) error {
10131013 return nil
10141014}
10151015
1016+ func (p * BlobPool ) flushTransactionsBelowTip (tip * uint256.Int ) {
1017+ for addr , txs := range p .index {
1018+ for i , tx := range txs {
1019+ if tx .execTipCap .Cmp (tip ) < 0 {
1020+ // Drop the offending transaction
1021+ var (
1022+ ids = []uint64 {tx .id }
1023+ nonces = []uint64 {tx .nonce }
1024+ )
1025+ p .spent [addr ] = new (uint256.Int ).Sub (p .spent [addr ], txs [i ].costCap )
1026+ p .stored -= uint64 (tx .size )
1027+ delete (p .lookup , tx .hash )
1028+ txs [i ] = nil
1029+
1030+ // Drop everything afterwards, no gaps allowed
1031+ for j , tx := range txs [i + 1 :] {
1032+ ids = append (ids , tx .id )
1033+ nonces = append (nonces , tx .nonce )
1034+
1035+ p .spent [addr ] = new (uint256.Int ).Sub (p .spent [addr ], tx .costCap )
1036+ p .stored -= uint64 (tx .size )
1037+ delete (p .lookup , tx .hash )
1038+ txs [i + 1 + j ] = nil
1039+ }
1040+ // Clear out the dropped transactions from the index
1041+ if i > 0 {
1042+ p .index [addr ] = txs [:i ]
1043+ heap .Fix (p .evict , p .evict .index [addr ])
1044+ } else {
1045+ delete (p .index , addr )
1046+ delete (p .spent , addr )
1047+
1048+ heap .Remove (p .evict , p .evict .index [addr ])
1049+ p .reserve (addr , false )
1050+ }
1051+ // Clear out the transactions from the data store
1052+ log .Warn ("Dropping underpriced blob transaction" , "from" , addr , "rejected" , tx .nonce , "tip" , tx .execTipCap , "want" , tip , "drop" , nonces , "ids" , ids )
1053+ dropUnderpricedMeter .Mark (int64 (len (ids )))
1054+
1055+ for _ , id := range ids {
1056+ if err := p .store .Delete (id ); err != nil {
1057+ log .Error ("Failed to delete dropped transaction" , "id" , id , "err" , err )
1058+ }
1059+ }
1060+ break
1061+ }
1062+ }
1063+ }
1064+ }
1065+
10161066// SetGasTip implements txpool.SubPool, allowing the blob pool's gas requirements
10171067// to be kept in sync with the main transaction pool's gas requirements.
10181068func (p * BlobPool ) SetGasTip (tip * big.Int ) {
@@ -1025,59 +1075,20 @@ func (p *BlobPool) SetGasTip(tip *big.Int) {
10251075
10261076 // If the min miner fee increased, remove transactions below the new threshold
10271077 if old == nil || p .gasTip .Cmp (old ) > 0 {
1028- for addr , txs := range p .index {
1029- for i , tx := range txs {
1030- if tx .execTipCap .Cmp (p .gasTip ) < 0 {
1031- // Drop the offending transaction
1032- var (
1033- ids = []uint64 {tx .id }
1034- nonces = []uint64 {tx .nonce }
1035- )
1036- p .spent [addr ] = new (uint256.Int ).Sub (p .spent [addr ], txs [i ].costCap )
1037- p .stored -= uint64 (tx .size )
1038- delete (p .lookup , tx .hash )
1039- txs [i ] = nil
1040-
1041- // Drop everything afterwards, no gaps allowed
1042- for j , tx := range txs [i + 1 :] {
1043- ids = append (ids , tx .id )
1044- nonces = append (nonces , tx .nonce )
1045-
1046- p .spent [addr ] = new (uint256.Int ).Sub (p .spent [addr ], tx .costCap )
1047- p .stored -= uint64 (tx .size )
1048- delete (p .lookup , tx .hash )
1049- txs [i + 1 + j ] = nil
1050- }
1051- // Clear out the dropped transactions from the index
1052- if i > 0 {
1053- p .index [addr ] = txs [:i ]
1054- heap .Fix (p .evict , p .evict .index [addr ])
1055- } else {
1056- delete (p .index , addr )
1057- delete (p .spent , addr )
1058-
1059- heap .Remove (p .evict , p .evict .index [addr ])
1060- p .reserve (addr , false )
1061- }
1062- // Clear out the transactions from the data store
1063- log .Warn ("Dropping underpriced blob transaction" , "from" , addr , "rejected" , tx .nonce , "tip" , tx .execTipCap , "want" , tip , "drop" , nonces , "ids" , ids )
1064- dropUnderpricedMeter .Mark (int64 (len (ids )))
1065-
1066- for _ , id := range ids {
1067- if err := p .store .Delete (id ); err != nil {
1068- log .Error ("Failed to delete dropped transaction" , "id" , id , "err" , err )
1069- }
1070- }
1071- break
1072- }
1073- }
1074- }
1078+ p .flushTransactionsBelowTip (p .gasTip )
10751079 }
10761080 log .Debug ("Blobpool tip threshold updated" , "tip" , tip )
10771081 pooltipGauge .Update (tip .Int64 ())
10781082 p .updateStorageMetrics ()
10791083}
10801084
1085+ func (p * BlobPool ) FlushAllTransactions () {
1086+ maxUint256 := uint256 .MustFromBig (new (big.Int ).Sub (new (big.Int ).Lsh (common .Big1 , 256 ), common .Big1 ))
1087+ p .lock .Lock ()
1088+ defer p .lock .Unlock ()
1089+ p .flushTransactionsBelowTip (maxUint256 )
1090+ }
1091+
10811092// validateTx checks whether a transaction is valid according to the consensus
10821093// rules and adheres to some heuristic limits of the local node (price and size).
10831094func (p * BlobPool ) validateTx (tx * types.Transaction ) error {
0 commit comments