Skip to content

Commit

Permalink
Merge branch 'syncUpstream/active' into syncUpstream/6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop authored Aug 13, 2024
2 parents 0ca888b + 763bc05 commit 64c4616
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- name: Build
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Install rust
uses: actions-rs/toolchain@v1
with:
Expand All @@ -55,7 +55,7 @@ jobs:
# - name: Install Go
# uses: actions/setup-go@v2
# with:
# go-version: 1.20.x
# go-version: 1.21.x
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Lint
Expand All @@ -69,7 +69,7 @@ jobs:
# - name: Install Go
# uses: actions/setup-go@v2
# with:
# go-version: 1.20.x
# go-version: 1.21.x
# - name: Install goimports
# run: go install golang.org/x/tools/cmd/goimports@latest
# - name: Checkout code
Expand All @@ -89,7 +89,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Checkout code
uses: actions/checkout@v2
- name: Test
Expand Down
5 changes: 3 additions & 2 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,9 @@ func (pool *LegacyPool) add(tx *types.Transaction, local bool) (replaced bool, e
// If the transaction pool is full, discard underpriced transactions
if uint64(pool.all.Slots()+numSlots(tx)) > pool.config.GlobalSlots+pool.config.GlobalQueue {
// If the new transaction is underpriced, don't accept it
if !isLocal && pool.priced.Underpriced(tx) {
log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
// if !isLocal && pool.priced.Underpriced(tx) {
if !isLocal && tx.GasFeeCapIntCmp(pool.gasTip.Load()) < 0 {
log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap(), "txPoolGasTip", pool.gasTip.Load())
underpricedTxMeter.Mark(1)
return false, txpool.ErrUnderpriced
}
Expand Down
4 changes: 2 additions & 2 deletions core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
}
// Ensure the gasprice is high enough to cover the requirement of the calling
// pool and/or block producer
if tx.GasTipCapIntCmp(opts.MinTip) < 0 {
return fmt.Errorf("%w: tip needed %v, tip permitted %v", ErrUnderpriced, opts.MinTip, tx.GasTipCap())
if tx.GasFeeCapIntCmp(opts.MinTip) < 0 {
return fmt.Errorf("%w: fee needed %v, fee permitted %v", ErrUnderpriced, opts.MinTip, tx.GasFeeCap())
}
// Ensure blob transactions have valid commitments
if tx.Type() == types.BlobTxType {
Expand Down
36 changes: 36 additions & 0 deletions core/types/row_consumption.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "slices"

type RowUsage struct {
IsOk bool `json:"is_ok"`
RowNumber uint64 `json:"row_number"`
Expand All @@ -12,4 +14,38 @@ type SubCircuitRowUsage struct {
RowNumber uint64 `json:"row_number" gencodec:"required"`
}

// RowConsumptionLimit is the max number of row we support per subcircuit
const RowConsumptionLimit = 1_000_000

type RowConsumption []SubCircuitRowUsage

// IsOverflown returns if any subcircuits are overflown
func (rc RowConsumption) IsOverflown() bool {
return slices.ContainsFunc(rc, func(scru SubCircuitRowUsage) bool {
return scru.RowNumber > RowConsumptionLimit
})
}

// Difference returns rc - other
// Assumes that rc > other for all subcircuits
func (rc RowConsumption) Difference(other RowConsumption) RowConsumption {
subCircuitMap := make(map[string]uint64, len(rc))
for _, detail := range rc {
subCircuitMap[detail.Name] = detail.RowNumber
}

for _, detail := range other {
subCircuitMap[detail.Name] -= detail.RowNumber
}

diff := make([]SubCircuitRowUsage, 0, len(subCircuitMap))
for name, rowNumDiff := range subCircuitMap {
if rowNumDiff > 0 {
diff = append(diff, SubCircuitRowUsage{
Name: name,
RowNumber: rowNumDiff,
})
}
}
return diff
}
80 changes: 80 additions & 0 deletions core/types/row_consumption_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package types

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestRowConsumptionDifference(t *testing.T) {
tests := []struct {
rc1 RowConsumption
rc2 RowConsumption
expected RowConsumption
}{
{
rc1: RowConsumption{
SubCircuitRowUsage{
"sc1",
123,
},
SubCircuitRowUsage{
"sc2",
456,
},
},
rc2: RowConsumption{
SubCircuitRowUsage{
"sc2",
111,
},
},
expected: RowConsumption{
SubCircuitRowUsage{
"sc1",
123,
},
SubCircuitRowUsage{
"sc2",
345,
},
},
},
{
rc1: RowConsumption{
SubCircuitRowUsage{
"sc1",
123,
},
SubCircuitRowUsage{
"sc2",
456,
},
},
rc2: RowConsumption{
SubCircuitRowUsage{
"sc2",
456,
},
},
expected: RowConsumption{
SubCircuitRowUsage{
"sc1",
123,
},
},
},
}

makeMap := func(rc RowConsumption) map[string]uint64 {
m := make(map[string]uint64)
for _, usage := range rc {
m[usage.Name] = usage.RowNumber
}
return m
}

for _, test := range tests {
assert.Equal(t, makeMap(test.expected), makeMap(test.rc1.Difference(test.rc2)))
}
}

0 comments on commit 64c4616

Please sign in to comment.