Skip to content

Commit 98708ac

Browse files
authored
Merge pull request #2 from ethereum/master
consensus/misc/eip4844: expose TargetBlobsPerBlock (#32991)
2 parents ebcb5e7 + 3d2a4cb commit 98708ac

File tree

12 files changed

+102
-35
lines changed

12 files changed

+102
-35
lines changed

build/ci.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ var (
107107
Tags: "ziren",
108108
Env: map[string]string{"GOMIPS": "softfloat", "CGO_ENABLED": "0"},
109109
},
110+
{
111+
Name: "wasm-js",
112+
GOOS: "js",
113+
GOARCH: "wasm",
114+
Tags: "example",
115+
},
116+
{
117+
Name: "wasm-wasi",
118+
GOOS: "wasip1",
119+
GOARCH: "wasm",
120+
Tags: "example",
121+
},
110122
{
111123
Name: "example",
112124
Tags: "example",
@@ -331,6 +343,10 @@ func buildFlags(env build.Environment, staticLinking bool, buildTags []string) (
331343
}
332344
ld = append(ld, "-extldflags", "'"+strings.Join(extld, " ")+"'")
333345
}
346+
// TODO(gballet): revisit after the input api has been defined
347+
if runtime.GOARCH == "wasm" {
348+
ld = append(ld, "-gcflags=all=-d=softfloat")
349+
}
334350
if len(ld) > 0 {
335351
flags = append(flags, "-ldflags", strings.Join(ld, " "))
336352
}

consensus/misc/eip4844/eip4844.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
200200
return bcfg.Max
201201
}
202202

203+
// TargetBlobsPerBlock returns the target blobs per block for a block at the given timestamp.
204+
func TargetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
205+
blobConfig := latestBlobConfig(cfg, time)
206+
if blobConfig == nil {
207+
return 0
208+
}
209+
return blobConfig.Target
210+
}
211+
203212
// fakeExponential approximates factor * e ** (numerator / denominator) using
204213
// Taylor expansion.
205214
func fakeExponential(factor, numerator, denominator *big.Int) *big.Int {

core/blockchain_insert.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,6 @@ func (it *insertIterator) next() (*types.Block, error) {
131131
return it.chain[it.index], it.validator.ValidateBody(it.chain[it.index])
132132
}
133133

134-
// peek returns the next block in the iterator, along with any potential validation
135-
// error for that block, but does **not** advance the iterator.
136-
//
137-
// Both header and body validation errors (nil too) is cached into the iterator
138-
// to avoid duplicating work on the following next() call.
139-
// nolint:unused
140-
func (it *insertIterator) peek() (*types.Block, error) {
141-
// If we reached the end of the chain, abort
142-
if it.index+1 >= len(it.chain) {
143-
return nil, nil
144-
}
145-
// Wait for verification result if not yet done
146-
if len(it.errors) <= it.index+1 {
147-
it.errors = append(it.errors, <-it.results)
148-
}
149-
if it.errors[it.index+1] != nil {
150-
return it.chain[it.index+1], it.errors[it.index+1]
151-
}
152-
// Block header valid, ignore body validation since we don't have a parent anyway
153-
return it.chain[it.index+1], nil
154-
}
155-
156134
// previous returns the previous header that was being processed, or nil.
157135
func (it *insertIterator) previous() *types.Header {
158136
if it.index < 1 {

core/rawdb/eradb/eradb.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ func (db *Store) openEraFile(epoch uint64) (*era.Era, error) {
303303
}
304304
// Sanity-check start block.
305305
if e.Start()%uint64(era.MaxEra1Size) != 0 {
306+
e.Close()
306307
return nil, fmt.Errorf("pre-merge era1 file has invalid boundary. %d %% %d != 0", e.Start(), era.MaxEra1Size)
307308
}
308309
log.Debug("Opened era1 file", "epoch", epoch)

core/rawdb/freezer_batch.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,18 @@ func newFreezerBatch(f *Freezer) *freezerBatch {
5151

5252
// Append adds an RLP-encoded item of the given kind.
5353
func (batch *freezerBatch) Append(kind string, num uint64, item interface{}) error {
54-
return batch.tables[kind].Append(num, item)
54+
if table := batch.tables[kind]; table != nil {
55+
return table.Append(num, item)
56+
}
57+
return errUnknownTable
5558
}
5659

5760
// AppendRaw adds an item of the given kind.
5861
func (batch *freezerBatch) AppendRaw(kind string, num uint64, item []byte) error {
59-
return batch.tables[kind].AppendRaw(num, item)
62+
if table := batch.tables[kind]; table != nil {
63+
return table.AppendRaw(num, item)
64+
}
65+
return errUnknownTable
6066
}
6167

6268
// reset initializes the batch.

core/rawdb/freezer_table.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,7 @@ func (t *freezerTable) sizeNolock() (uint64, error) {
11961196
}
11971197

11981198
// advanceHead should be called when the current head file would outgrow the file limits,
1199-
// and a new file must be opened. The caller of this method must hold the write-lock
1200-
// before calling this method.
1199+
// and a new file must be opened. This method acquires the write-lock internally.
12011200
func (t *freezerTable) advanceHead() error {
12021201
t.lock.Lock()
12031202
defer t.lock.Unlock()
@@ -1218,7 +1217,9 @@ func (t *freezerTable) advanceHead() error {
12181217
return err
12191218
}
12201219
t.releaseFile(t.headId)
1221-
t.openFile(t.headId, openFreezerFileForReadOnly)
1220+
if _, err := t.openFile(t.headId, openFreezerFileForReadOnly); err != nil {
1221+
return err
1222+
}
12221223

12231224
// Swap out the current head.
12241225
t.head = newHead

core/state/statedb_hooked.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (s *hookedStateDB) SelfDestruct(address common.Address) uint256.Int {
220220
var prevCode []byte
221221
var prevCodeHash common.Hash
222222

223-
if s.hooks.OnCodeChange != nil {
223+
if s.hooks.OnCodeChange != nil || s.hooks.OnCodeChangeV2 != nil {
224224
prevCode = s.inner.GetCode(address)
225225
prevCodeHash = s.inner.GetCodeHash(address)
226226
}
@@ -246,7 +246,7 @@ func (s *hookedStateDB) SelfDestruct6780(address common.Address) (uint256.Int, b
246246
var prevCode []byte
247247
var prevCodeHash common.Hash
248248

249-
if s.hooks.OnCodeChange != nil {
249+
if s.hooks.OnCodeChange != nil || s.hooks.OnCodeChangeV2 != nil {
250250
prevCodeHash = s.inner.GetCodeHash(address)
251251
prevCode = s.inner.GetCode(address)
252252
}

core/state/statedb_hooked_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,47 @@ func TestHooks(t *testing.T) {
122122
sdb.AddLog(&types.Log{
123123
Address: common.Address{0xbb},
124124
})
125+
126+
if len(result) != len(wants) {
127+
t.Fatalf("number of tracing events wrong, have %d want %d", len(result), len(wants))
128+
}
129+
130+
for i, want := range wants {
131+
if have := result[i]; have != want {
132+
t.Fatalf("error event %d, have\n%v\nwant%v\n", i, have, want)
133+
}
134+
}
135+
}
136+
137+
func TestHooks_OnCodeChangeV2(t *testing.T) {
138+
inner, _ := New(types.EmptyRootHash, NewDatabaseForTesting())
139+
140+
var result []string
141+
var wants = []string{
142+
"0xaa00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728) ContractCreation",
143+
"0xaa00000000000000000000000000000000000000.code: 0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728) -> (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) SelfDestruct",
144+
"0xbb00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1326 (0x3c54516221d604e623f358bc95996ca3242aaa109bddabcebda13db9b3f90dcb) ContractCreation",
145+
"0xbb00000000000000000000000000000000000000.code: 0x1326 (0x3c54516221d604e623f358bc95996ca3242aaa109bddabcebda13db9b3f90dcb) -> (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) SelfDestruct",
146+
}
147+
emitF := func(format string, a ...any) {
148+
result = append(result, fmt.Sprintf(format, a...))
149+
}
150+
sdb := NewHookedState(inner, &tracing.Hooks{
151+
OnCodeChangeV2: func(addr common.Address, prevCodeHash common.Hash, prevCode []byte, codeHash common.Hash, code []byte, reason tracing.CodeChangeReason) {
152+
emitF("%v.code: %#x (%v) ->%#x (%v) %s", addr, prevCode, prevCodeHash, code, codeHash, reason)
153+
},
154+
})
155+
sdb.SetCode(common.Address{0xaa}, []byte{0x13, 37}, tracing.CodeChangeContractCreation)
156+
sdb.SelfDestruct(common.Address{0xaa})
157+
158+
sdb.SetCode(common.Address{0xbb}, []byte{0x13, 38}, tracing.CodeChangeContractCreation)
159+
sdb.CreateContract(common.Address{0xbb})
160+
sdb.SelfDestruct6780(common.Address{0xbb})
161+
162+
if len(result) != len(wants) {
163+
t.Fatalf("number of tracing events wrong, have %d want %d", len(result), len(wants))
164+
}
165+
125166
for i, want := range wants {
126167
if have := result[i]; have != want {
127168
t.Fatalf("error event %d, have\n%v\nwant%v\n", i, have, want)

eth/catalyst/simulated_beacon.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,8 @@ func (c *SimulatedBeacon) loop() {
280280
case <-timer.C:
281281
if err := c.sealBlock(c.withdrawals.pop(10), uint64(time.Now().Unix())); err != nil {
282282
log.Warn("Error performing sealing work", "err", err)
283-
} else {
284-
timer.Reset(time.Second * time.Duration(c.period))
285283
}
284+
timer.Reset(time.Second * time.Duration(c.period))
286285
}
287286
}
288287
}

eth/tracers/native/mux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ func (t *muxTracer) OnCodeChange(a common.Address, prevCodeHash common.Hash, pre
156156
}
157157
}
158158

159+
func (t *muxTracer) OnCodeChangeV2(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte, reason tracing.CodeChangeReason) {
160+
for _, t := range t.tracers {
161+
if t.OnCodeChangeV2 != nil {
162+
t.OnCodeChangeV2(a, prevCodeHash, prev, codeHash, code, reason)
163+
}
164+
}
165+
}
166+
159167
func (t *muxTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {
160168
for _, t := range t.tracers {
161169
if t.OnStorageChange != nil {

0 commit comments

Comments
 (0)