Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mev: add TxIndex for mev bid #2325

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches:
- master
- develop
- blobtx

jobs:
unit-test:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches:
- master
- develop
- blobtx

jobs:
commitlint:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/evm-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches:
- master
- develop
- blobtx

jobs:
evm-test:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches:
- master
- develop
- blobtx

jobs:
truffle-test:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches:
- master
- develop
- blobtx

jobs:
golang-lint:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
branches:
- master
- develop
- blobtx

jobs:
unit-test:
Expand Down
2 changes: 2 additions & 0 deletions core/rawdb/ancient_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var chainFreezerNoSnappy = map[string]bool{
ChainFreezerBlobSidecarTable: false,
}

var additionTables = []string{ChainFreezerBlobSidecarTable}

const (
// stateHistoryTableSize defines the maximum size of freezer data files.
stateHistoryTableSize = 2 * 1000 * 1000 * 1000
Expand Down
9 changes: 0 additions & 9 deletions core/rawdb/chain_freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,6 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash
return hashes, err
}

// EmptyBlobAncient check if empty in blob ancient, it is used to init blob ancient
func EmptyBlobAncient(f *chainFreezer) (bool, error) {
frozen, err := f.TableAncients(ChainFreezerBlobSidecarTable)
if err != nil {
return false, err
}
return frozen == 0, nil
}

func (f *chainFreezer) SetupFreezerEnv(env *ethdb.FreezerEnv) error {
f.freezeEnv.Store(env)
return nil
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func NewDatabase(db ethdb.KeyValueStore) ethdb.Database {
// NewFreezerDb only create a freezer without statedb.
func NewFreezerDb(db ethdb.KeyValueStore, frz, namespace string, readonly bool, newOffSet uint64) (*Freezer, error) {
// Create the idle freezer instance, this operation should be atomic to avoid mismatch between offset and acientDB.
frdb, err := NewFreezer(frz, namespace, readonly, newOffSet, freezerTableSize, chainFreezerNoSnappy, ChainFreezerBlobSidecarTable)
frdb, err := NewFreezer(frz, namespace, readonly, newOffSet, freezerTableSize, chainFreezerNoSnappy)
if err != nil {
return nil, err
}
Expand Down
24 changes: 11 additions & 13 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ type Freezer struct {
instanceLock *flock.Flock // File-system lock to prevent double opens
closeOnce sync.Once
offset uint64 // Starting BlockNumber in current freezer

additionTableKinds []string // additionTableKinds are post-filled tables that start as empty
}

// NewChainFreezer is a small utility method around NewFreezer that sets the
// default parameters for the chain storage.
func NewChainFreezer(datadir string, namespace string, readonly bool, offset uint64) (*Freezer, error) {
return NewFreezer(datadir, namespace, readonly, offset, freezerTableSize, chainFreezerNoSnappy, ChainFreezerBlobSidecarTable)
return NewFreezer(datadir, namespace, readonly, offset, freezerTableSize, chainFreezerNoSnappy)
}

// NewFreezer creates a freezer instance for maintaining immutable ordered
Expand All @@ -93,7 +91,7 @@ func NewChainFreezer(datadir string, namespace string, readonly bool, offset uin
// The 'tables' argument defines the data tables. If the value of a map
// entry is true, snappy compression is disabled for the table.
// additionTables indicates the new add tables for freezerDB, it has some special rules.
func NewFreezer(datadir string, namespace string, readonly bool, offset uint64, maxTableSize uint32, tables map[string]bool, additionTables ...string) (*Freezer, error) {
func NewFreezer(datadir string, namespace string, readonly bool, offset uint64, maxTableSize uint32, tables map[string]bool) (*Freezer, error) {
// Create the initial freezer object
var (
readMeter = metrics.NewRegisteredMeter(namespace+"ancient/read", nil)
Expand Down Expand Up @@ -125,11 +123,10 @@ func NewFreezer(datadir string, namespace string, readonly bool, offset uint64,
}
// Open all the supported data tables
freezer := &Freezer{
readonly: readonly,
tables: make(map[string]*freezerTable),
instanceLock: lock,
offset: offset,
additionTableKinds: additionTables,
readonly: readonly,
tables: make(map[string]*freezerTable),
instanceLock: lock,
offset: offset,
}

// Create the tables.
Expand Down Expand Up @@ -415,7 +412,7 @@ func (f *Freezer) validate() error {
// Hack to get boundary of any table
for kind, table := range f.tables {
// addition tables is special cases
if slices.Contains(f.additionTableKinds, kind) {
if slices.Contains(additionTables, kind) {
continue
}
head = table.items.Load()
Expand All @@ -426,7 +423,7 @@ func (f *Freezer) validate() error {
// Now check every table against those boundaries.
for kind, table := range f.tables {
// check addition tables, try to align with exist tables
if slices.Contains(f.additionTableKinds, kind) {
if slices.Contains(additionTables, kind) {
// if the table is empty, just skip
if EmptyTable(table) {
continue
Expand Down Expand Up @@ -460,7 +457,7 @@ func (f *Freezer) repair() error {
)
for kind, table := range f.tables {
// addition tables only align head
if slices.Contains(f.additionTableKinds, kind) {
if slices.Contains(additionTables, kind) {
if EmptyTable(table) {
continue
}
Expand All @@ -481,7 +478,7 @@ func (f *Freezer) repair() error {
}
for kind, table := range f.tables {
// try to align with exist tables, skip empty table
if slices.Contains(f.additionTableKinds, kind) && EmptyTable(table) {
if slices.Contains(additionTables, kind) && EmptyTable(table) {
continue
}
err := table.truncateHead(head)
Expand Down Expand Up @@ -701,6 +698,7 @@ func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error {
return nil
}

// only used for ChainFreezerBlobSidecarTable now
func (f *Freezer) ResetTable(kind string, tail, head uint64, onlyEmpty bool) error {
if f.readonly {
return errReadOnly
Expand Down
8 changes: 3 additions & 5 deletions core/rawdb/freezer_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ const freezerBatchBufferLimit = 2 * 1024 * 1024

// freezerBatch is a write operation of multiple items on a freezer.
type freezerBatch struct {
tables map[string]*freezerTableBatch
additionTableKinds []string // additionTableKinds are post-filled tables that start as empty
tables map[string]*freezerTableBatch
}

func newFreezerBatch(f *Freezer) *freezerBatch {
batch := &freezerBatch{
tables: make(map[string]*freezerTableBatch, len(f.tables)),
additionTableKinds: f.additionTableKinds,
tables: make(map[string]*freezerTableBatch, len(f.tables)),
}
for kind, table := range f.tables {
batch.tables[kind] = table.newBatch(f.offset)
Expand Down Expand Up @@ -72,7 +70,7 @@ func (batch *freezerBatch) commit() (item uint64, writeSize int64, err error) {
item = uint64(math.MaxUint64)
for name, tb := range batch.tables {
// skip empty addition tables
if slices.Contains(batch.additionTableKinds, name) && EmptyTable(tb.t) {
if slices.Contains(additionTables, name) && EmptyTable(tb.t) {
continue
}
if item < math.MaxUint64 && tb.curItem != item {
Expand Down
1 change: 1 addition & 0 deletions core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ func (t *freezerTable) ResetItemsOffset(virtualTail uint64) error {
}

// resetItems reset freezer table head & tail
// only used for ChainFreezerBlobSidecarTable now
func (t *freezerTable) resetItems(tail, head uint64) (*freezerTable, error) {
if t.readonly {
return nil, errors.New("resetItems in readonly mode")
Expand Down
7 changes: 4 additions & 3 deletions core/rawdb/freezer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,12 @@ func TestFreezer_AdditionTables(t *testing.T) {
require.NoError(t, f.Close())

// check read only
f, err = NewFreezer(dir, "", true, 0, 2049, map[string]bool{"o1": true, "o2": true, "a1": true}, "a1")
additionTables = []string{"a1"}
f, err = NewFreezer(dir, "", true, 0, 2049, map[string]bool{"o1": true, "o2": true, "a1": true})
require.NoError(t, err)
require.NoError(t, f.Close())

f, err = NewFreezer(dir, "", false, 0, 2049, map[string]bool{"o1": true, "o2": true, "a1": true}, "a1")
f, err = NewFreezer(dir, "", false, 0, 2049, map[string]bool{"o1": true, "o2": true, "a1": true})
require.NoError(t, err)
frozen, _ := f.Ancients()
f.ResetTable("a1", frozen, frozen, true)
Expand All @@ -392,7 +393,7 @@ func TestFreezer_AdditionTables(t *testing.T) {
require.NoError(t, f.Close())

// reopen and read
f, err = NewFreezer(dir, "", true, 0, 2049, map[string]bool{"o1": true, "o2": true, "a1": true}, "a1")
f, err = NewFreezer(dir, "", true, 0, 2049, map[string]bool{"o1": true, "o2": true, "a1": true})
require.NoError(t, err)
actual, err = f.Ancient("a1", 2)
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ func (r *BidRuntime) commitTransaction(chain *core.BlockChain, chainConfig *para
}

if tx.Type() == types.BlobTxType {
sc.TxIndex = uint64(len(env.txs))
env.txs = append(env.txs, tx.WithoutBlobTxSidecar())
env.receipts = append(env.receipts, receipt)
env.sidecars = append(env.sidecars, sc)
Expand Down
Loading