mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
feat: allow calculating diffs between two row consumptions (#981)
* feat: allow calculating diffs between two row consumptions (#980) * bump go version in github CI --------- Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com>
This commit is contained in:
parent
7c6dd59108
commit
2f828ecdb3
3 changed files with 121 additions and 5 deletions
10
.github/workflows/ci.yml
vendored
10
.github/workflows/ci.yml
vendored
|
|
@ -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
|
||||
|
|
@ -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:
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package types
|
||||
|
||||
import "slices"
|
||||
|
||||
type RowUsage struct {
|
||||
IsOk bool `json:"is_ok"`
|
||||
RowNumber uint64 `json:"row_number"`
|
||||
|
|
@ -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
core/types/row_consumption_test.go
Normal file
80
core/types/row_consumption_test.go
Normal file
|
|
@ -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)))
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue