mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
Merge pull request #2 from ethereum/master
consensus/misc/eip4844: expose TargetBlobsPerBlock (#32991)
This commit is contained in:
commit
98708acdb6
12 changed files with 102 additions and 35 deletions
16
build/ci.go
16
build/ci.go
|
|
@ -107,6 +107,18 @@ var (
|
|||
Tags: "ziren",
|
||||
Env: map[string]string{"GOMIPS": "softfloat", "CGO_ENABLED": "0"},
|
||||
},
|
||||
{
|
||||
Name: "wasm-js",
|
||||
GOOS: "js",
|
||||
GOARCH: "wasm",
|
||||
Tags: "example",
|
||||
},
|
||||
{
|
||||
Name: "wasm-wasi",
|
||||
GOOS: "wasip1",
|
||||
GOARCH: "wasm",
|
||||
Tags: "example",
|
||||
},
|
||||
{
|
||||
Name: "example",
|
||||
Tags: "example",
|
||||
|
|
@ -331,6 +343,10 @@ func buildFlags(env build.Environment, staticLinking bool, buildTags []string) (
|
|||
}
|
||||
ld = append(ld, "-extldflags", "'"+strings.Join(extld, " ")+"'")
|
||||
}
|
||||
// TODO(gballet): revisit after the input api has been defined
|
||||
if runtime.GOARCH == "wasm" {
|
||||
ld = append(ld, "-gcflags=all=-d=softfloat")
|
||||
}
|
||||
if len(ld) > 0 {
|
||||
flags = append(flags, "-ldflags", strings.Join(ld, " "))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,6 +200,15 @@ func LatestMaxBlobsPerBlock(cfg *params.ChainConfig) int {
|
|||
return bcfg.Max
|
||||
}
|
||||
|
||||
// TargetBlobsPerBlock returns the target blobs per block for a block at the given timestamp.
|
||||
func TargetBlobsPerBlock(cfg *params.ChainConfig, time uint64) int {
|
||||
blobConfig := latestBlobConfig(cfg, time)
|
||||
if blobConfig == nil {
|
||||
return 0
|
||||
}
|
||||
return blobConfig.Target
|
||||
}
|
||||
|
||||
// fakeExponential approximates factor * e ** (numerator / denominator) using
|
||||
// Taylor expansion.
|
||||
func fakeExponential(factor, numerator, denominator *big.Int) *big.Int {
|
||||
|
|
|
|||
|
|
@ -131,28 +131,6 @@ func (it *insertIterator) next() (*types.Block, error) {
|
|||
return it.chain[it.index], it.validator.ValidateBody(it.chain[it.index])
|
||||
}
|
||||
|
||||
// peek returns the next block in the iterator, along with any potential validation
|
||||
// error for that block, but does **not** advance the iterator.
|
||||
//
|
||||
// Both header and body validation errors (nil too) is cached into the iterator
|
||||
// to avoid duplicating work on the following next() call.
|
||||
// nolint:unused
|
||||
func (it *insertIterator) peek() (*types.Block, error) {
|
||||
// If we reached the end of the chain, abort
|
||||
if it.index+1 >= len(it.chain) {
|
||||
return nil, nil
|
||||
}
|
||||
// Wait for verification result if not yet done
|
||||
if len(it.errors) <= it.index+1 {
|
||||
it.errors = append(it.errors, <-it.results)
|
||||
}
|
||||
if it.errors[it.index+1] != nil {
|
||||
return it.chain[it.index+1], it.errors[it.index+1]
|
||||
}
|
||||
// Block header valid, ignore body validation since we don't have a parent anyway
|
||||
return it.chain[it.index+1], nil
|
||||
}
|
||||
|
||||
// previous returns the previous header that was being processed, or nil.
|
||||
func (it *insertIterator) previous() *types.Header {
|
||||
if it.index < 1 {
|
||||
|
|
|
|||
|
|
@ -303,6 +303,7 @@ func (db *Store) openEraFile(epoch uint64) (*era.Era, error) {
|
|||
}
|
||||
// Sanity-check start block.
|
||||
if e.Start()%uint64(era.MaxEra1Size) != 0 {
|
||||
e.Close()
|
||||
return nil, fmt.Errorf("pre-merge era1 file has invalid boundary. %d %% %d != 0", e.Start(), era.MaxEra1Size)
|
||||
}
|
||||
log.Debug("Opened era1 file", "epoch", epoch)
|
||||
|
|
|
|||
|
|
@ -51,12 +51,18 @@ func newFreezerBatch(f *Freezer) *freezerBatch {
|
|||
|
||||
// Append adds an RLP-encoded item of the given kind.
|
||||
func (batch *freezerBatch) Append(kind string, num uint64, item interface{}) error {
|
||||
return batch.tables[kind].Append(num, item)
|
||||
if table := batch.tables[kind]; table != nil {
|
||||
return table.Append(num, item)
|
||||
}
|
||||
return errUnknownTable
|
||||
}
|
||||
|
||||
// AppendRaw adds an item of the given kind.
|
||||
func (batch *freezerBatch) AppendRaw(kind string, num uint64, item []byte) error {
|
||||
return batch.tables[kind].AppendRaw(num, item)
|
||||
if table := batch.tables[kind]; table != nil {
|
||||
return table.AppendRaw(num, item)
|
||||
}
|
||||
return errUnknownTable
|
||||
}
|
||||
|
||||
// reset initializes the batch.
|
||||
|
|
|
|||
|
|
@ -1196,8 +1196,7 @@ func (t *freezerTable) sizeNolock() (uint64, error) {
|
|||
}
|
||||
|
||||
// advanceHead should be called when the current head file would outgrow the file limits,
|
||||
// and a new file must be opened. The caller of this method must hold the write-lock
|
||||
// before calling this method.
|
||||
// and a new file must be opened. This method acquires the write-lock internally.
|
||||
func (t *freezerTable) advanceHead() error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
|
@ -1218,7 +1217,9 @@ func (t *freezerTable) advanceHead() error {
|
|||
return err
|
||||
}
|
||||
t.releaseFile(t.headId)
|
||||
t.openFile(t.headId, openFreezerFileForReadOnly)
|
||||
if _, err := t.openFile(t.headId, openFreezerFileForReadOnly); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Swap out the current head.
|
||||
t.head = newHead
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ func (s *hookedStateDB) SelfDestruct(address common.Address) uint256.Int {
|
|||
var prevCode []byte
|
||||
var prevCodeHash common.Hash
|
||||
|
||||
if s.hooks.OnCodeChange != nil {
|
||||
if s.hooks.OnCodeChange != nil || s.hooks.OnCodeChangeV2 != nil {
|
||||
prevCode = s.inner.GetCode(address)
|
||||
prevCodeHash = s.inner.GetCodeHash(address)
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ func (s *hookedStateDB) SelfDestruct6780(address common.Address) (uint256.Int, b
|
|||
var prevCode []byte
|
||||
var prevCodeHash common.Hash
|
||||
|
||||
if s.hooks.OnCodeChange != nil {
|
||||
if s.hooks.OnCodeChange != nil || s.hooks.OnCodeChangeV2 != nil {
|
||||
prevCodeHash = s.inner.GetCodeHash(address)
|
||||
prevCode = s.inner.GetCode(address)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,6 +122,47 @@ func TestHooks(t *testing.T) {
|
|||
sdb.AddLog(&types.Log{
|
||||
Address: common.Address{0xbb},
|
||||
})
|
||||
|
||||
if len(result) != len(wants) {
|
||||
t.Fatalf("number of tracing events wrong, have %d want %d", len(result), len(wants))
|
||||
}
|
||||
|
||||
for i, want := range wants {
|
||||
if have := result[i]; have != want {
|
||||
t.Fatalf("error event %d, have\n%v\nwant%v\n", i, have, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestHooks_OnCodeChangeV2(t *testing.T) {
|
||||
inner, _ := New(types.EmptyRootHash, NewDatabaseForTesting())
|
||||
|
||||
var result []string
|
||||
var wants = []string{
|
||||
"0xaa00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728) ContractCreation",
|
||||
"0xaa00000000000000000000000000000000000000.code: 0x1325 (0xa12ae05590de0c93a00bc7ac773c2fdb621e44f814985e72194f921c0050f728) -> (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) SelfDestruct",
|
||||
"0xbb00000000000000000000000000000000000000.code: (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) ->0x1326 (0x3c54516221d604e623f358bc95996ca3242aaa109bddabcebda13db9b3f90dcb) ContractCreation",
|
||||
"0xbb00000000000000000000000000000000000000.code: 0x1326 (0x3c54516221d604e623f358bc95996ca3242aaa109bddabcebda13db9b3f90dcb) -> (0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470) SelfDestruct",
|
||||
}
|
||||
emitF := func(format string, a ...any) {
|
||||
result = append(result, fmt.Sprintf(format, a...))
|
||||
}
|
||||
sdb := NewHookedState(inner, &tracing.Hooks{
|
||||
OnCodeChangeV2: func(addr common.Address, prevCodeHash common.Hash, prevCode []byte, codeHash common.Hash, code []byte, reason tracing.CodeChangeReason) {
|
||||
emitF("%v.code: %#x (%v) ->%#x (%v) %s", addr, prevCode, prevCodeHash, code, codeHash, reason)
|
||||
},
|
||||
})
|
||||
sdb.SetCode(common.Address{0xaa}, []byte{0x13, 37}, tracing.CodeChangeContractCreation)
|
||||
sdb.SelfDestruct(common.Address{0xaa})
|
||||
|
||||
sdb.SetCode(common.Address{0xbb}, []byte{0x13, 38}, tracing.CodeChangeContractCreation)
|
||||
sdb.CreateContract(common.Address{0xbb})
|
||||
sdb.SelfDestruct6780(common.Address{0xbb})
|
||||
|
||||
if len(result) != len(wants) {
|
||||
t.Fatalf("number of tracing events wrong, have %d want %d", len(result), len(wants))
|
||||
}
|
||||
|
||||
for i, want := range wants {
|
||||
if have := result[i]; have != want {
|
||||
t.Fatalf("error event %d, have\n%v\nwant%v\n", i, have, want)
|
||||
|
|
|
|||
|
|
@ -280,9 +280,8 @@ func (c *SimulatedBeacon) loop() {
|
|||
case <-timer.C:
|
||||
if err := c.sealBlock(c.withdrawals.pop(10), uint64(time.Now().Unix())); err != nil {
|
||||
log.Warn("Error performing sealing work", "err", err)
|
||||
} else {
|
||||
timer.Reset(time.Second * time.Duration(c.period))
|
||||
}
|
||||
timer.Reset(time.Second * time.Duration(c.period))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,14 @@ func (t *muxTracer) OnCodeChange(a common.Address, prevCodeHash common.Hash, pre
|
|||
}
|
||||
}
|
||||
|
||||
func (t *muxTracer) OnCodeChangeV2(a common.Address, prevCodeHash common.Hash, prev []byte, codeHash common.Hash, code []byte, reason tracing.CodeChangeReason) {
|
||||
for _, t := range t.tracers {
|
||||
if t.OnCodeChangeV2 != nil {
|
||||
t.OnCodeChangeV2(a, prevCodeHash, prev, codeHash, code, reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *muxTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {
|
||||
for _, t := range t.tracers {
|
||||
if t.OnStorageChange != nil {
|
||||
|
|
|
|||
14
rpc/http.go
14
rpc/http.go
|
|
@ -168,13 +168,21 @@ func newClientTransportHTTP(endpoint string, cfg *clientConfig) reconnectFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// cleanlyCloseBody avoids sending unnecessary RST_STREAM and PING frames by
|
||||
// ensuring the whole body is read before being closed.
|
||||
// See https://blog.cloudflare.com/go-and-enhance-your-calm/#reading-bodies-in-go-can-be-unintuitive
|
||||
func cleanlyCloseBody(body io.ReadCloser) error {
|
||||
io.Copy(io.Discard, body)
|
||||
return body.Close()
|
||||
}
|
||||
|
||||
func (c *Client) sendHTTP(ctx context.Context, op *requestOp, msg interface{}) error {
|
||||
hc := c.writeConn.(*httpConn)
|
||||
respBody, err := hc.doRequest(ctx, msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer respBody.Close()
|
||||
defer cleanlyCloseBody(respBody)
|
||||
|
||||
var resp jsonrpcMessage
|
||||
batch := [1]*jsonrpcMessage{&resp}
|
||||
|
|
@ -191,7 +199,7 @@ func (c *Client) sendBatchHTTP(ctx context.Context, op *requestOp, msgs []*jsonr
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer respBody.Close()
|
||||
defer cleanlyCloseBody(respBody)
|
||||
|
||||
var respmsgs []*jsonrpcMessage
|
||||
if err := json.NewDecoder(respBody).Decode(&respmsgs); err != nil {
|
||||
|
|
@ -236,7 +244,7 @@ func (hc *httpConn) doRequest(ctx context.Context, msg interface{}) (io.ReadClos
|
|||
if _, err := buf.ReadFrom(resp.Body); err == nil {
|
||||
body = buf.Bytes()
|
||||
}
|
||||
resp.Body.Close()
|
||||
cleanlyCloseBody(resp.Body)
|
||||
return nil, HTTPError{
|
||||
Status: resp.Status,
|
||||
StatusCode: resp.StatusCode,
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ func confirmHTTPRequestYieldsStatusCode(t *testing.T, method, contentType, body
|
|||
if err != nil {
|
||||
t.Fatalf("request failed: %v", err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
cleanlyCloseBody(resp.Body)
|
||||
confirmStatusCode(t, resp.StatusCode, expectedStatusCode)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue