From 2568cf3acf09f410efe584c4797b1318de4f7c91 Mon Sep 17 00:00:00 2001 From: tak Date: Thu, 10 Oct 2024 14:04:26 +0800 Subject: [PATCH 01/22] support eth67 --- eth/protocols/eth/broadcast.go | 13 ++++++++++--- eth/protocols/eth/handler.go | 5 ++++- eth/protocols/eth/handlers.go | 17 +++++++++++++++++ eth/protocols/eth/peer.go | 12 ++++++++++++ eth/protocols/eth/protocol.go | 9 +++++++-- 5 files changed, 50 insertions(+), 6 deletions(-) diff --git a/eth/protocols/eth/broadcast.go b/eth/protocols/eth/broadcast.go index ad5395cb8..b8224577d 100644 --- a/eth/protocols/eth/broadcast.go +++ b/eth/protocols/eth/broadcast.go @@ -163,9 +163,16 @@ func (p *Peer) announceTransactions() { if len(pending) > 0 { done = make(chan struct{}) go func() { - if err := p.sendPooledTransactionHashes(pending, pendingTypes, pendingSizes); err != nil { - fail <- err - return + if p.version >= ETH68 { + if err := p.sendPooledTransactionHashes(pending, pendingTypes, pendingSizes); err != nil { + fail <- err + return + } + } else { + if err := p.sendPooledTransactionHashes66(pending); err != nil { + fail <- err + return + } } close(done) p.Log().Trace("Sent transaction announcements", "count", len(pending)) diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go index 801fae223..40d3f7d04 100644 --- a/eth/protocols/eth/handler.go +++ b/eth/protocols/eth/handler.go @@ -93,6 +93,10 @@ type TxPool interface { func MakeProtocols(backend Backend, network uint64, dnsdisc enode.Iterator) []p2p.Protocol { protocols := make([]p2p.Protocol, 0, len(ProtocolVersions)) for _, version := range ProtocolVersions { + // Blob transactions require eth/68 announcements, disable everything else + if version <= ETH67 && backend.Chain().Config().CancunTime != nil { + continue + } version := version // Closure protocols = append(protocols, p2p.Protocol{ @@ -209,7 +213,6 @@ func handleMessage(backend Backend, peer *Peer) error { if peer.Version() >= ETH68 { handlers = eth68 } - // Track the amount of time it takes to serve the request and run the handler if metrics.Enabled { h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code) diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index 0275708a6..f0cdbc004 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -383,6 +383,23 @@ func handleReceipts(backend Backend, msg Decoder, peer *Peer) error { }, metadata) } +func handleNewPooledTransactionHashes67(backend Backend, msg Decoder, peer *Peer) error { + // New transaction announcement arrived, make sure we have + // a valid and fresh chain to handle them + if !backend.AcceptTxs() { + return nil + } + ann := new(NewPooledTransactionHashesPacket67) + if err := msg.Decode(ann); err != nil { + return fmt.Errorf("%w: message %v: %v", errDecode, msg, err) + } + // Schedule all the unknown hashes for retrieval + for _, hash := range *ann { + peer.markTransaction(hash) + } + return backend.Handle(peer, ann) +} + func handleNewPooledTransactionHashes(backend Backend, msg Decoder, peer *Peer) error { // New transaction announcement arrived, make sure we have // a valid and fresh chain to handle them diff --git a/eth/protocols/eth/peer.go b/eth/protocols/eth/peer.go index ffd78b059..b150e0504 100644 --- a/eth/protocols/eth/peer.go +++ b/eth/protocols/eth/peer.go @@ -210,6 +210,18 @@ func (p *Peer) AsyncSendTransactions(hashes []common.Hash) { } } +// sendPooledTransactionHashes66 sends transaction hashes to the peer and includes +// them in its transaction hash set for future reference. +// +// This method is a helper used by the async transaction announcer. Don't call it +// directly as the queueing (memory) and transmission (bandwidth) costs should +// not be managed directly. +func (p *Peer) sendPooledTransactionHashes66(hashes []common.Hash) error { + // Mark all the transactions as known, but ensure we don't overflow our limits + p.knownTxs.Add(hashes...) + return p2p.Send(p.rw, NewPooledTransactionHashesMsg, NewPooledTransactionHashesPacket67(hashes)) +} + // sendPooledTransactionHashes sends transaction hashes (tagged with their type // and size) to the peer and includes them in its transaction hash set for future // reference. diff --git a/eth/protocols/eth/protocol.go b/eth/protocols/eth/protocol.go index ad5c2e748..2c819a463 100644 --- a/eth/protocols/eth/protocol.go +++ b/eth/protocols/eth/protocol.go @@ -283,6 +283,9 @@ type ReceiptsRLPPacket struct { ReceiptsRLPResponse } +// NewPooledTransactionHashesPacket67 represents a transaction announcement packet on eth/67. +type NewPooledTransactionHashesPacket67 []common.Hash + // NewPooledTransactionHashesPacket represents a transaction announcement packet on eth/68 and newer. type NewPooledTransactionHashesPacket struct { Types []byte @@ -343,8 +346,10 @@ func (*BlockBodiesResponse) Kind() byte { return BlockBodiesMsg } func (*NewBlockPacket) Name() string { return "NewBlock" } func (*NewBlockPacket) Kind() byte { return NewBlockMsg } -func (*NewPooledTransactionHashesPacket) Name() string { return "NewPooledTransactionHashes" } -func (*NewPooledTransactionHashesPacket) Kind() byte { return NewPooledTransactionHashesMsg } +func (*NewPooledTransactionHashesPacket67) Name() string { return "NewPooledTransactionHashes" } +func (*NewPooledTransactionHashesPacket67) Kind() byte { return NewPooledTransactionHashesMsg } +func (*NewPooledTransactionHashesPacket) Name() string { return "NewPooledTransactionHashes" } +func (*NewPooledTransactionHashesPacket) Kind() byte { return NewPooledTransactionHashesMsg } func (*GetPooledTransactionsRequest) Name() string { return "GetPooledTransactions" } func (*GetPooledTransactionsRequest) Kind() byte { return GetPooledTransactionsMsg } From 55774346632fc749ef52cdef6d6cca4198b9ef61 Mon Sep 17 00:00:00 2001 From: tak Date: Thu, 17 Oct 2024 10:54:42 +0800 Subject: [PATCH 02/22] secured go.mod --- Makefile | 4 +--- README.md | 11 ---------- go.mod | 26 ----------------------- go.sum | 63 ++++--------------------------------------------------- 4 files changed, 5 insertions(+), 99 deletions(-) diff --git a/Makefile b/Makefile index 68fd02877..24e686f25 100644 --- a/Makefile +++ b/Makefile @@ -22,13 +22,11 @@ all: test: all $(GORUN) build/ci.go test -<<<<<<< HEAD +#? test-oasys: Run Oasys consensus tests test-oasys: go test -v ./consensus/oasys/... -======= #? lint: Run certain pre-selected linters ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 lint: ## Run linters. $(GORUN) build/ci.go lint diff --git a/README.md b/README.md index 18e5c0bf9..85e83dd6f 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,12 @@ -<<<<<<< HEAD ![logo1](https://user-images.githubusercontent.com/107421475/227834490-3a3a9834-21a8-4079-8166-f6fe571d6b8d.png) # Oasys Validator Validator client for Oasys. Forked from go ethereum. -======= -## Go Ethereum - -Golang execution layer implementation of the Ethereum protocol. ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 [![API Reference]( https://pkg.go.dev/badge/github.com/ethereum/go-ethereum )](https://pkg.go.dev/github.com/ethereum/go-ethereum?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/ethereum/go-ethereum)](https://goreportcard.com/report/github.com/ethereum/go-ethereum) -<<<<<<< HEAD [![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/oasysgames) -======= -[![Travis](https://app.travis-ci.com/ethereum/go-ethereum.svg?branch=master)](https://app.travis-ci.com/github/ethereum/go-ethereum) -[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/nthXNEv) ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 Automated builds are available for stable releases and the unstable master branch. Binary archives are published at https://github.com/oasysgames/oasys-validator/releases. diff --git a/go.mod b/go.mod index f3063c8b4..9153f5231 100644 --- a/go.mod +++ b/go.mod @@ -37,12 +37,8 @@ require ( github.com/gorilla/websocket v1.5.1 github.com/graph-gophers/graphql-go v1.3.0 github.com/hashicorp/go-bexpr v0.1.10 -<<<<<<< HEAD github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d - github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 -======= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/holiman/bloomfilter/v2 v2.0.3 github.com/holiman/uint256 v1.2.4 github.com/huin/goupnp v1.3.0 @@ -75,17 +71,10 @@ require ( github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3 github.com/willf/bitset v1.1.3 go.uber.org/automaxprocs v1.5.2 -<<<<<<< HEAD golang.org/x/crypto v0.19.0 golang.org/x/exp v0.0.0-20240213143201-ec583247a57a golang.org/x/sync v0.6.0 golang.org/x/sys v0.17.0 -======= - golang.org/x/crypto v0.17.0 - golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa - golang.org/x/sync v0.5.0 - golang.org/x/sys v0.16.0 ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 golang.org/x/text v0.14.0 golang.org/x/time v0.5.0 golang.org/x/tools v0.18.0 @@ -131,20 +120,15 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/dustin/go-humanize v1.0.0 // indirect github.com/elastic/gosigar v0.14.2 // indirect - github.com/ferranbt/fastssz v0.0.0-20210120143747-11b9eff30ea9 // indirect github.com/flynn/noise v1.1.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect -<<<<<<< HEAD github.com/getsentry/sentry-go v0.25.0 // indirect github.com/go-logr/logr v1.3.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.13.0 // indirect -======= - github.com/go-ole/go-ole v1.3.0 // indirect ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/goccy/go-json v0.10.2 // indirect @@ -172,7 +156,6 @@ require ( github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a // indirect github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213 // indirect github.com/kilic/bls12-381 v0.1.0 // indirect -<<<<<<< HEAD github.com/klauspost/compress v1.17.6 // indirect github.com/klauspost/cpuid/v2 v2.2.7 // indirect github.com/koron/go-ssdp v0.0.4 // indirect @@ -202,15 +185,6 @@ require ( github.com/minio/highwayhash v1.0.2 // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect -======= - github.com/klauspost/compress v1.15.15 // indirect - github.com/klauspost/cpuid/v2 v2.0.9 // indirect - github.com/kr/pretty v0.3.1 // indirect - github.com/kr/text v0.2.0 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect - github.com/minio/sha256-simd v1.0.0 // indirect ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/mitchellh/mapstructure v1.4.1 // indirect github.com/mitchellh/pointerstructure v1.2.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect diff --git a/go.sum b/go.sum index a66202623..6a966e38f 100644 --- a/go.sum +++ b/go.sum @@ -301,13 +301,13 @@ github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= -<<<<<<< HEAD -github.com/ferranbt/fastssz v0.0.0-20210120143747-11b9eff30ea9 h1:9VDpsWq096+oGMDTT/SgBD/VgZYf4pTF+KTPmZ+OaKM= github.com/ferranbt/fastssz v0.0.0-20210120143747-11b9eff30ea9/go.mod h1:DyEu2iuLBnb/T51BlsiO3yLYdJC6UbGMrIkqK1KmQxM= +github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk= +github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c= -github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= +github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= +github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= @@ -318,16 +318,6 @@ github.com/francoispqt/gojay v1.2.13/go.mod h1:ehT5mTG4ua4581f1++1WLG0vPdaA9HaiD github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= -======= -github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk= -github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs= -github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY= -github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= -github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= -github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= -github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= @@ -359,7 +349,6 @@ github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgO github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -<<<<<<< HEAD github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -370,12 +359,6 @@ github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= -======= -github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= -github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= -github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= -github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= @@ -574,7 +557,6 @@ github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:i github.com/hashicorp/golang-lru/v2 v2.0.5 h1:wW7h1TG88eUIJ2i69gaE3uNVtEPIagzhGvHgwfx2Vm4= github.com/hashicorp/golang-lru/v2 v2.0.5/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= -<<<<<<< HEAD github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= @@ -582,12 +564,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/herumi/bls-eth-go-binary v0.0.0-20210130185500-57372fb27371/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e h1:wCMygKUQhmcQAjlk2Gquzq6dLmyMv2kF+llRspoRgrk= github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= -github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZKHF9GxxWKDJGj8I0IqOUol//sw= -github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= -======= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA= github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= @@ -654,7 +632,6 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -<<<<<<< HEAD github.com/klauspost/compress v1.9.8/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.1/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= @@ -665,16 +642,6 @@ github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuV github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/klauspost/reedsolomon v1.9.3/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= -======= -github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= -github.com/klauspost/compress v1.15.15 h1:EF27CXIuDsYJ6mmvtBRlEuB2UVOqHG1tAXgZ7yIO+lw= -github.com/klauspost/compress v1.15.15/go.mod h1:ZcK2JAFqKOpnBlxcLsJzYfrS9X1akm9fHZNnD9+Vo/4= -github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -767,7 +734,6 @@ github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -<<<<<<< HEAD github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4= @@ -792,15 +758,6 @@ github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceT github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -======= -github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= -github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg= -github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQGvsUt6O3Pj+LDCQ= -github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc= -github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= -github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= @@ -993,7 +950,6 @@ github.com/prometheus/prom2json v1.3.0/go.mod h1:rMN7m0ApCowcoDlypBHlkNbp5eJQf/+ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7 h1:cZC+usqsYgHtlBaGulVnZ1hfKAi8iWtujBnRLQE698c= github.com/protolambda/bls12-381-util v0.0.0-20220416220906-d8552aa452c7/go.mod h1:IToEjHuttnUzwZI5KBSM/LOOW3qLbbrHOEfp3SbECGY= -<<<<<<< HEAD github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44 h1:c3p3UzV4vFA7xaCDphnDWOjpxcadrQ26l5b+ypsvyxo= github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44/go.mod h1:MA5zShstUwCQaE9faGHgCGvEWUbG87p4SAXINhmCkvg= github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7 h1:0tVE4tdWQK9ZpYygoV7+vS6QkDvQVySboMVEIxBJmXw= @@ -1018,10 +974,6 @@ github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtB github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -======= -github.com/prysmaticlabs/gohashtree v0.0.1-alpha.0.20220714111606-acbb2962fb48 h1:cSo6/vk8YpvkLbk9v3FO97cakNmUoxwi2KMP8hd5WIw= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -1486,17 +1438,10 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -<<<<<<< HEAD golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -======= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= ->>>>>>> c5ba367eb6232e3eddd7d6226bfd374449c63164 golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= From 3acdf47bbd8425d28a9d1ea3e7ea2096bd164cb7 Mon Sep 17 00:00:00 2001 From: tak Date: Thu, 17 Oct 2024 12:53:15 +0800 Subject: [PATCH 03/22] fix compile error --- consensus/oasys/contract.go | 3 ++- consensus/oasys/contract_test.go | 4 ++-- consensus/oasys/oasys.go | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/consensus/oasys/contract.go b/consensus/oasys/contract.go index 8ee246f23..fcabba5d0 100644 --- a/consensus/oasys/contract.go +++ b/consensus/oasys/contract.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" + "github.com/holiman/uint256" ) const ( @@ -796,7 +797,7 @@ func applyMessage( *msg.To(), msg.Data(), msg.Gas(), - msg.Value(), + uint256.MustFromBig(msg.Value()), ) if err != nil { log.Error("failed apply message", "msg", string(ret), "err", err) diff --git a/consensus/oasys/contract_test.go b/consensus/oasys/contract_test.go index d976f7f71..fba30c198 100644 --- a/consensus/oasys/contract_test.go +++ b/consensus/oasys/contract_test.go @@ -601,11 +601,11 @@ func makeEnv(wallet accounts.Wallet, account accounts.Account) (*testEnv, error) } // Generate StateDB - _, _, statedb := tests.MakePreState(db, genspec.Alloc, false, rawdb.HashScheme) + stateTestState := tests.MakePreState(db, genspec.Alloc, false, rawdb.HashScheme) // Replace artifact bytecode environment.artifact.DeployedBytecode = fmt.Sprintf("0x%s", hex.EncodeToString(genspec.Alloc[_environmentAddress].Code)) stakeManager.artifact.DeployedBytecode = fmt.Sprintf("0x%s", hex.EncodeToString(genspec.Alloc[_stakeManagerAddress].Code)) - return &testEnv{engine, chain, statedb}, nil + return &testEnv{engine, chain, stateTestState.StateDB}, nil } diff --git a/consensus/oasys/oasys.go b/consensus/oasys/oasys.go index 11fc9a27c..872d2560c 100644 --- a/consensus/oasys/oasys.go +++ b/consensus/oasys/oasys.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/trie" lru "github.com/hashicorp/golang-lru" + "github.com/holiman/uint256" "github.com/prysmaticlabs/prysm/v5/crypto/bls" "github.com/willf/bitset" "golang.org/x/crypto/sha3" @@ -1477,7 +1478,7 @@ func (c *Oasys) addBalanceToStakeManager(state *state.StateDB, hash common.Hash, return nil } - state.AddBalance(stakeManager.address, rewards) + state.AddBalance(stakeManager.address, uint256.MustFromBig(rewards)) log.Info("Balance added to stake manager", "hash", hash, "amount", rewards.String()) return nil } From 703c75299403be9961fe07544affd4dc0394b59a Mon Sep 17 00:00:00 2001 From: tak Date: Thu, 17 Oct 2024 12:55:16 +0800 Subject: [PATCH 04/22] upgrade wealdtech/go-eth2-types/v2 from v2.5.2 to v2.8.1, to avoid bnb forked fastssz --- go.mod | 8 ++++---- go.sum | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 9153f5231..865a1044b 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 github.com/ethereum/c-kzg-4844 v0.4.0 github.com/fatih/color v1.13.0 - github.com/ferranbt/fastssz v0.1.2 + github.com/ferranbt/fastssz v0.1.3 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fjl/memsize v0.0.2 github.com/fsnotify/fsnotify v1.6.0 @@ -146,7 +146,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect - github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e // indirect + github.com/herumi/bls-eth-go-binary v1.29.1 // indirect github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect @@ -185,7 +185,7 @@ require ( github.com/minio/highwayhash v1.0.2 // indirect github.com/minio/sha256-simd v1.0.1 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect - github.com/mitchellh/mapstructure v1.4.1 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/mitchellh/pointerstructure v1.2.0 // indirect github.com/mmcloughlin/addchain v0.4.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -239,7 +239,7 @@ require ( github.com/trailofbits/go-mutexasserts v0.0.0-20230328101604-8cdbc5f3d279 // indirect github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect github.com/wealdtech/go-bytesutil v1.1.1 // indirect - github.com/wealdtech/go-eth2-types/v2 v2.5.2 // indirect + github.com/wealdtech/go-eth2-types/v2 v2.8.1 // indirect github.com/wealdtech/go-eth2-util v1.6.3 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect diff --git a/go.sum b/go.sum index 6a966e38f..a94478cd1 100644 --- a/go.sum +++ b/go.sum @@ -302,8 +302,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/ferranbt/fastssz v0.0.0-20210120143747-11b9eff30ea9/go.mod h1:DyEu2iuLBnb/T51BlsiO3yLYdJC6UbGMrIkqK1KmQxM= -github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk= -github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs= +github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo= +github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= @@ -562,8 +562,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/herumi/bls-eth-go-binary v0.0.0-20210130185500-57372fb27371/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= -github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e h1:wCMygKUQhmcQAjlk2Gquzq6dLmyMv2kF+llRspoRgrk= -github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= +github.com/herumi/bls-eth-go-binary v1.29.1 h1:XcNSHYTyNjEUVfWDCE2gtG5r95biTwd7MJUJF09LtSE= +github.com/herumi/bls-eth-go-binary v1.29.1/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= @@ -765,8 +765,9 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.3.2/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.2.0 h1:O+i9nHnXS3l/9Wu7r4NrEdwA2VFTicjUEN1uBnDo34A= github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8ohIXc3tViBH44KcwB2g4= github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= @@ -1108,6 +1109,8 @@ github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2n github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/uber/jaeger-client-go v2.25.0+incompatible h1:IxcNZ7WRY1Y3G4poYlx24szfsn/3LvK9QHCq9oQw8+U= github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= +github.com/umbracle/gohashtree v0.0.2-alpha.0.20230207094856-5b775a815c10 h1:CQh33pStIp/E30b7TxDlXfM0145bn2e8boI30IxAhTg= +github.com/umbracle/gohashtree v0.0.2-alpha.0.20230207094856-5b775a815c10/go.mod h1:x/Pa0FF5Te9kdrlZKJK82YmAkvL8+f989USgz6Jiw7M= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= @@ -1120,8 +1123,9 @@ github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49u github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM= github.com/wealdtech/go-bytesutil v1.1.1 h1:ocEg3Ke2GkZ4vQw5lp46rmO+pfqCCTgq35gqOy8JKVc= github.com/wealdtech/go-bytesutil v1.1.1/go.mod h1:jENeMqeTEU8FNZyDFRVc7KqBdRKSnJ9CCh26TcuNb9s= -github.com/wealdtech/go-eth2-types/v2 v2.5.2 h1:tiA6T88M6XQIbrV5Zz53l1G5HtRERcxQfmET225V4Ls= github.com/wealdtech/go-eth2-types/v2 v2.5.2/go.mod h1:8lkNUbgklSQ4LZ2oMSuxSdR7WwJW3L9ge1dcoCVyzws= +github.com/wealdtech/go-eth2-types/v2 v2.8.1 h1:y2N3xSIZ3tVqsnvj4AgPkh48U5sM612vhZwlK3k+3lM= +github.com/wealdtech/go-eth2-types/v2 v2.8.1/go.mod h1:3TJShI4oBzG8pCZsfe3NZAq8QAmXrC2rd45q7Vn/XB8= github.com/wealdtech/go-eth2-util v1.6.3 h1:2INPeOR35x5LdFFpSzyw954WzTD+DFyHe3yKlJnG5As= github.com/wealdtech/go-eth2-util v1.6.3/go.mod h1:0hFMj/qtio288oZFHmAbCnPQ9OB3c4WFzs5NVPKTY4k= github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3 h1:SxrDVSr+oXuT1x8kZt4uWqNCvv5xXEGV9zd7cuSrZS8= From 09ab3c86100bda746544605bc79678fefa3a642c Mon Sep 17 00:00:00 2001 From: tak Date: Thu, 17 Oct 2024 13:41:37 +0800 Subject: [PATCH 05/22] downgrade github.com/wealdtech/go-eth2-types to v2.6.0, to kept github.com/ferranbt/fastssz version as v0.1.2 --- go.mod | 4 ++-- go.sum | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 865a1044b..6aa845f79 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 github.com/ethereum/c-kzg-4844 v0.4.0 github.com/fatih/color v1.13.0 - github.com/ferranbt/fastssz v0.1.3 + github.com/ferranbt/fastssz v0.1.2 github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e github.com/fjl/memsize v0.0.2 github.com/fsnotify/fsnotify v1.6.0 @@ -239,7 +239,7 @@ require ( github.com/trailofbits/go-mutexasserts v0.0.0-20230328101604-8cdbc5f3d279 // indirect github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect github.com/wealdtech/go-bytesutil v1.1.1 // indirect - github.com/wealdtech/go-eth2-types/v2 v2.8.1 // indirect + github.com/wealdtech/go-eth2-types/v2 v2.7.0 // indirect github.com/wealdtech/go-eth2-util v1.6.3 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect diff --git a/go.sum b/go.sum index a94478cd1..e79cb8cc6 100644 --- a/go.sum +++ b/go.sum @@ -302,8 +302,9 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/ferranbt/fastssz v0.0.0-20210120143747-11b9eff30ea9/go.mod h1:DyEu2iuLBnb/T51BlsiO3yLYdJC6UbGMrIkqK1KmQxM= -github.com/ferranbt/fastssz v0.1.3 h1:ZI+z3JH05h4kgmFXdHuR1aWYsgrg7o+Fw7/NCzM16Mo= -github.com/ferranbt/fastssz v0.1.3/go.mod h1:0Y9TEd/9XuFlh7mskMPfXiI2Dkw4Ddg9EyXt1W7MRvE= +github.com/ferranbt/fastssz v0.1.1/go.mod h1:U2ZsxlYyvGeQGmadhz8PlEqwkBzDIhHwd3xuKrg2JIs= +github.com/ferranbt/fastssz v0.1.2 h1:Dky6dXlngF6Qjc+EfDipAkE83N5I5DE68bY6O0VLNPk= +github.com/ferranbt/fastssz v0.1.2/go.mod h1:X5UPrE2u1UJjxHA8X54u04SBwdAQjG2sFtWs39YxyWs= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e h1:bBLctRc7kr01YGvaDfgLbTwjFNW5jdp5y5rj8XXBHfY= github.com/fjl/gencodec v0.0.0-20230517082657-f9840df7b83e/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY= github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= @@ -439,6 +440,7 @@ github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb h1:PBC98N2aIaM3XXiurYmW7fx4GZkL8feAMVq7nEjURHk= github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -562,6 +564,7 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/herumi/bls-eth-go-binary v0.0.0-20210130185500-57372fb27371/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= +github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/herumi/bls-eth-go-binary v1.29.1 h1:XcNSHYTyNjEUVfWDCE2gtG5r95biTwd7MJUJF09LtSE= github.com/herumi/bls-eth-go-binary v1.29.1/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= @@ -638,6 +641,8 @@ github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYs github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/klauspost/pgzip v1.2.5/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= @@ -752,6 +757,7 @@ github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= +github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM= github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -1109,8 +1115,6 @@ github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2n github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/uber/jaeger-client-go v2.25.0+incompatible h1:IxcNZ7WRY1Y3G4poYlx24szfsn/3LvK9QHCq9oQw8+U= github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= -github.com/umbracle/gohashtree v0.0.2-alpha.0.20230207094856-5b775a815c10 h1:CQh33pStIp/E30b7TxDlXfM0145bn2e8boI30IxAhTg= -github.com/umbracle/gohashtree v0.0.2-alpha.0.20230207094856-5b775a815c10/go.mod h1:x/Pa0FF5Te9kdrlZKJK82YmAkvL8+f989USgz6Jiw7M= github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= @@ -1124,8 +1128,8 @@ github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMI github.com/wealdtech/go-bytesutil v1.1.1 h1:ocEg3Ke2GkZ4vQw5lp46rmO+pfqCCTgq35gqOy8JKVc= github.com/wealdtech/go-bytesutil v1.1.1/go.mod h1:jENeMqeTEU8FNZyDFRVc7KqBdRKSnJ9CCh26TcuNb9s= github.com/wealdtech/go-eth2-types/v2 v2.5.2/go.mod h1:8lkNUbgklSQ4LZ2oMSuxSdR7WwJW3L9ge1dcoCVyzws= -github.com/wealdtech/go-eth2-types/v2 v2.8.1 h1:y2N3xSIZ3tVqsnvj4AgPkh48U5sM612vhZwlK3k+3lM= -github.com/wealdtech/go-eth2-types/v2 v2.8.1/go.mod h1:3TJShI4oBzG8pCZsfe3NZAq8QAmXrC2rd45q7Vn/XB8= +github.com/wealdtech/go-eth2-types/v2 v2.7.0 h1:TV2jrNkane2nxTiVhyG3npVtg825WvRdCZZ4j+jTENA= +github.com/wealdtech/go-eth2-types/v2 v2.7.0/go.mod h1:aQ5dk+KNPE/A2r3lLhKpW+f5B24aJO68tRz6wO4Zo/g= github.com/wealdtech/go-eth2-util v1.6.3 h1:2INPeOR35x5LdFFpSzyw954WzTD+DFyHe3yKlJnG5As= github.com/wealdtech/go-eth2-util v1.6.3/go.mod h1:0hFMj/qtio288oZFHmAbCnPQ9OB3c4WFzs5NVPKTY4k= github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3 h1:SxrDVSr+oXuT1x8kZt4uWqNCvv5xXEGV9zd7cuSrZS8= @@ -1436,8 +1440,10 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 24c8643ee74362d66093aa03a5f1420f79c73be2 Mon Sep 17 00:00:00 2001 From: tak Date: Thu, 17 Oct 2024 13:45:45 +0800 Subject: [PATCH 06/22] rever back github.com/herumi/bls-eth-go-binary original version --- go.mod | 2 +- go.sum | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6aa845f79..2fcba9932 100644 --- a/go.mod +++ b/go.mod @@ -146,7 +146,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-retryablehttp v0.7.4 // indirect github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect - github.com/herumi/bls-eth-go-binary v1.29.1 // indirect + github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e // indirect github.com/influxdata/line-protocol v0.0.0-20210311194329-9aa0e372d097 // indirect github.com/ipfs/go-cid v0.4.1 // indirect github.com/ipfs/go-log/v2 v2.5.1 // indirect diff --git a/go.sum b/go.sum index e79cb8cc6..e77de38cc 100644 --- a/go.sum +++ b/go.sum @@ -564,9 +564,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= github.com/herumi/bls-eth-go-binary v0.0.0-20210130185500-57372fb27371/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= +github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e h1:wCMygKUQhmcQAjlk2Gquzq6dLmyMv2kF+llRspoRgrk= github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= -github.com/herumi/bls-eth-go-binary v1.29.1 h1:XcNSHYTyNjEUVfWDCE2gtG5r95biTwd7MJUJF09LtSE= -github.com/herumi/bls-eth-go-binary v1.29.1/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 h1:X4egAf/gcS1zATw6wn4Ej8vjuVGxeHdan+bRb2ebyv4= github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4/go.mod h1:5GuXa7vkL8u9FkFuWdVvfR5ix8hRB7DbOAaYULamFpc= github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= From 84db9b4e86a7d3eb16fac8ffa54e4c921f9018b9 Mon Sep 17 00:00:00 2001 From: tak Date: Tue, 22 Oct 2024 23:08:54 +0800 Subject: [PATCH 07/22] integrate bsc cancun support --- beacon/engine/types.go | 2 +- cmd/geth/config.go | 11 ++ cmd/geth/main.go | 4 + cmd/utils/flags.go | 38 +++++ consensus/clique/clique.go | 2 +- consensus/consensus.go | 3 + consensus/oasys/oasys.go | 68 +++++--- core/blockchain.go | 48 ++++++ core/blockchain_reader.go | 17 ++ core/chain_makers.go | 31 ++++ core/data_availability.go | 162 ++++++++++++++++++ core/headerchain.go | 4 + core/rawdb/accessors_chain.go | 113 ++++++++++++ core/rawdb/ancient_scheme.go | 16 +- core/rawdb/chain_freezer.go | 153 ++++++++++++++++- core/rawdb/database.go | 26 ++- core/rawdb/freezer.go | 171 ++++++++++++++++++- core/rawdb/freezer_batch.go | 6 + core/rawdb/freezer_resettable.go | 16 ++ core/rawdb/freezer_table.go | 55 +++++- core/rawdb/schema.go | 8 +- core/rawdb/table.go | 14 ++ core/state_transition.go | 7 + core/types/blob_sidecar.go | 94 ++++++++++ core/types/block.go | 39 +++++ core/types/tx_blob.go | 6 +- eth/api_backend.go | 4 + eth/backend.go | 7 + eth/catalyst/api_test.go | 10 +- eth/downloader/downloader.go | 23 ++- eth/downloader/fetchers_concurrent_bodies.go | 4 +- eth/downloader/queue.go | 14 +- eth/downloader/queue_test.go | 2 +- eth/downloader/testchain_test.go | 4 +- eth/ethconfig/config.go | 6 +- eth/fetcher/block_fetcher.go | 23 +-- eth/gasprice/gasprice_test.go | 2 +- eth/handler_eth.go | 11 +- eth/protocols/eth/broadcast.go | 2 +- eth/protocols/eth/handlers.go | 21 ++- eth/protocols/eth/peer.go | 5 +- eth/protocols/eth/protocol.go | 22 ++- ethclient/ethclient.go | 20 +++ ethdb/database.go | 24 ++- ethdb/remotedb/remotedb.go | 14 ++ internal/ethapi/api.go | 80 +++++++++ internal/ethapi/api_test.go | 8 + internal/ethapi/backend.go | 1 + internal/ethapi/transaction_args_test.go | 3 + internal/web3ext/web3ext.go | 10 ++ miner/payload_building.go | 2 +- miner/worker.go | 36 ++-- params/config.go | 12 +- params/network_params.go | 14 +- params/protocol_params.go | 5 + 55 files changed, 1389 insertions(+), 114 deletions(-) create mode 100644 core/data_availability.go create mode 100644 core/types/blob_sidecar.go diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 60accc3c7..7ccc0d5b3 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -263,7 +263,7 @@ func ExecutableDataToBlock(params ExecutableData, versionedHashes []common.Hash, // BlockToExecutableData constructs the ExecutableData structure by filling the // fields from the given block. It assumes the given block is post-merge block. -func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.BlobTxSidecar) *ExecutionPayloadEnvelope { +func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars types.BlobSidecars) *ExecutionPayloadEnvelope { data := &ExecutableData{ BlockHash: block.Hash(), ParentHash: block.ParentHash(), diff --git a/cmd/geth/config.go b/cmd/geth/config.go index dd89e2370..eb42c8b41 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -35,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/eth/catalyst" + "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/internal/flags" @@ -177,6 +178,16 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) { v := ctx.Uint64(utils.OverrideVerkle.Name) cfg.Eth.OverrideVerkle = &v } + if ctx.IsSet(utils.OverrideFullImmutabilityThreshold.Name) { + params.FullImmutabilityThreshold = ctx.Uint64(utils.OverrideFullImmutabilityThreshold.Name) + downloader.FullMaxForkAncestry = ctx.Uint64(utils.OverrideFullImmutabilityThreshold.Name) + } + if ctx.IsSet(utils.OverrideMinBlocksForBlobRequests.Name) { + params.MinBlocksForBlobRequests = ctx.Uint64(utils.OverrideMinBlocksForBlobRequests.Name) + } + if ctx.IsSet(utils.OverrideDefaultExtraReserveForBlobRequests.Name) { + params.DefaultExtraReserveForBlobRequests = ctx.Uint64(utils.OverrideDefaultExtraReserveForBlobRequests.Name) + } backend, eth := utils.RegisterEthService(stack, &cfg.Eth) // Create gauge with geth system and build information diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 37768e344..5dbc81eb8 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -67,6 +67,9 @@ var ( utils.SmartCardDaemonPathFlag, utils.OverrideCancun, utils.OverrideVerkle, + utils.OverrideFullImmutabilityThreshold, + utils.OverrideMinBlocksForBlobRequests, + utils.OverrideDefaultExtraReserveForBlobRequests, utils.EnablePersonal, utils.TxPoolLocalsFlag, utils.TxPoolNoLocalsFlag, @@ -153,6 +156,7 @@ var ( utils.VoteKeyNameFlag, utils.LogDebugFlag, utils.LogBacktraceAtFlag, + utils.BlobExtraReserveFlag, }, utils.NetworkFlags, utils.DatabaseFlags) rpcFlags = []cli.Flag{ diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 6191fdbaf..912ff5503 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -252,6 +252,24 @@ var ( Usage: "Manually specify the Verkle fork timestamp, overriding the bundled setting", Category: flags.EthCategory, } + OverrideFullImmutabilityThreshold = &cli.Uint64Flag{ + Name: "override.immutabilitythreshold", + Usage: "It is the number of blocks after which a chain segment is considered immutable, only for testing purpose", + Value: params.FullImmutabilityThreshold, + Category: flags.EthCategory, + } + OverrideMinBlocksForBlobRequests = &cli.Uint64Flag{ + Name: "override.minforblobrequest", + Usage: "It keeps blob data available for min blocks in local, only for testing purpose", + Value: params.MinBlocksForBlobRequests, + Category: flags.EthCategory, + } + OverrideDefaultExtraReserveForBlobRequests = &cli.Uint64Flag{ + Name: "override.defaultextrareserve", + Usage: "It adds more extra time for expired blobs for some request cases, only for testing purpose", + Value: params.DefaultExtraReserveForBlobRequests, + Category: flags.EthCategory, + } SyncModeFlag = &flags.TextMarshalerFlag{ Name: "syncmode", Usage: `Blockchain sync mode ("snap" or "full")`, @@ -949,6 +967,14 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server. Usage: "Name of the BLS public key used for voting (default = first found key)", Category: flags.FastFinalityCategory, } + + // Blob setting + BlobExtraReserveFlag = &cli.Uint64Flag{ + Name: "blob.extra-reserve", + Usage: "Extra reserve threshold for blob, blob never expires when 0 is set, default 28800", + Value: params.DefaultExtraReserveForBlobRequests, + Category: flags.MiscCategory, + } ) var ( @@ -1939,6 +1965,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { if err := kzg4844.UseCKZG(ctx.String(CryptoKZGFlag.Name) == "ckzg"); err != nil { Fatalf("Failed to set KZG library implementation to %s: %v", ctx.String(CryptoKZGFlag.Name), err) } + + // blob setting + if ctx.IsSet(OverrideDefaultExtraReserveForBlobRequests.Name) { + cfg.BlobExtraReserve = ctx.Uint64(OverrideDefaultExtraReserveForBlobRequests.Name) + } + if ctx.IsSet(BlobExtraReserveFlag.Name) { + extraReserve := ctx.Uint64(BlobExtraReserveFlag.Name) + if extraReserve > 0 && extraReserve < params.DefaultExtraReserveForBlobRequests { + extraReserve = params.DefaultExtraReserveForBlobRequests + } + cfg.BlobExtraReserve = extraReserve + } } // SetDNSDiscoveryDefaults configures DNS discovery with the given URL if diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 1363ffa86..8a73b4d72 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -406,7 +406,7 @@ func (c *Clique) snapshot(chain consensus.ChainHeaderReader, number uint64, hash // at a checkpoint block without a parent (light client CHT), or we have piled // up more headers than allowed to be reorged (chain reinit from a freezer), // consider the checkpoint trusted and snapshot it. - if number == 0 || (number%c.config.Epoch == 0 && (len(headers) > params.FullImmutabilityThreshold || chain.GetHeaderByNumber(number-1) == nil)) { + if number == 0 || (number%c.config.Epoch == 0 && (len(headers) > int(params.FullImmutabilityThreshold) || chain.GetHeaderByNumber(number-1) == nil)) { checkpoint := chain.GetHeaderByNumber(number) if checkpoint != nil { hash := checkpoint.Hash() diff --git a/consensus/consensus.go b/consensus/consensus.go index 968b2d158..503e5bf65 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -50,6 +50,9 @@ type ChainHeaderReader interface { // GetCanonicalHash returns the canonical hash for a given block number GetCanonicalHash(number uint64) common.Hash + + // ChasingHead return the best chain head of peers. + ChasingHead() *types.Header } type VotePool interface { diff --git a/consensus/oasys/oasys.go b/consensus/oasys/oasys.go index 872d2560c..c373ca1d0 100644 --- a/consensus/oasys/oasys.go +++ b/consensus/oasys/oasys.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" + "github.com/ethereum/go-ethereum/consensus/misc/eip4844" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" @@ -309,22 +310,51 @@ func (c *Oasys) verifyHeader(chain consensus.ChainHeaderReader, header *types.He if header.GasLimit > params.MaxGasLimit { return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit) } - // Verify the non-existence of withdrawalsHash. - if header.WithdrawalsHash != nil { - return fmt.Errorf("invalid withdrawalsHash: have %x, expected nil", header.WithdrawalsHash) + + parent, err := c.getParent(chain, header, parents) + if err != nil { + return err } - if chain.Config().IsCancun(header.Number, header.Time) { - return errors.New("oasys does not support cancun fork") + + // Verify the block's gas usage and (if applicable) verify the base fee. + if !chain.Config().IsLondon(header.Number) { + // Verify BaseFee not present before EIP-1559 fork. + if header.BaseFee != nil { + return fmt.Errorf("invalid baseFee before fork: have %d, want ", header.BaseFee) + } + if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil { + return err + } + } else if err := eip1559.VerifyEIP1559Header(chain.Config(), parent, header); err != nil { + // Verify the header's EIP-1559 attributes. + return err } - // Verify the non-existence of cancun-specific header fields - switch { - case header.ExcessBlobGas != nil: - return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas) - case header.BlobGasUsed != nil: - return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed) - case header.ParentBeaconRoot != nil: - return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot) + // Verify the existence / non-existence of cancun-specific header fields + cancun := chain.Config().IsCancun(header.Number, header.Time) + if !cancun { + switch { + case header.ExcessBlobGas != nil: + return fmt.Errorf("invalid excessBlobGas: have %d, expected nil", header.ExcessBlobGas) + case header.BlobGasUsed != nil: + return fmt.Errorf("invalid blobGasUsed: have %d, expected nil", header.BlobGasUsed) + case header.ParentBeaconRoot != nil: + return fmt.Errorf("invalid parentBeaconRoot, have %#x, expected nil", header.ParentBeaconRoot) + case header.WithdrawalsHash != nil: + return fmt.Errorf("invalid WithdrawalsHash, have %#x, expected nil", header.WithdrawalsHash) + } + } else { + switch { + case !header.EmptyWithdrawalsHash(): + return errors.New("header has wrong WithdrawalsHash") + } + if header.ParentBeaconRoot == nil { + return errors.New("header is missing beaconRoot") + } + if err := eip4844.VerifyEIP4844Header(parent, header); err != nil { + return err + } } + // All basic checks passed, verify cascading fields return c.verifyCascadingFields(chain, header, parents, snap, env) } @@ -369,18 +399,6 @@ func (c *Oasys) verifyCascadingFields(chain consensus.ChainHeaderReader, header if header.GasUsed > header.GasLimit { return fmt.Errorf("invalid gasUsed: have %d, gasLimit %d", header.GasUsed, header.GasLimit) } - if !chain.Config().IsLondon(header.Number) { - // Verify BaseFee not present before EIP-1559 fork. - if header.BaseFee != nil { - return fmt.Errorf("invalid baseFee before fork: have %d, want ", header.BaseFee) - } - if err := misc.VerifyGaslimit(parent.GasLimit, header.GasLimit); err != nil { - return err - } - } else if err := eip1559.VerifyEIP1559Header(chain.Config(), parent, header); err != nil { - // Verify the header's EIP-1559 attributes. - return err - } // Verify vote attestation for fast finality. if err := c.verifyVoteAttestation(chain, header, parents, env); err != nil { diff --git a/core/blockchain.go b/core/blockchain.go index 1323a4fde..908f62ec0 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -101,6 +101,7 @@ const ( bodyCacheLimit = 256 blockCacheLimit = 256 receiptsCacheLimit = 32 + sidecarsCacheLimit = 256 txLookupCacheLimit = 1024 maxFutureBlocks = 256 maxTimeFutureBlocks = 30 @@ -240,12 +241,14 @@ type BlockChain struct { currentBlock atomic.Pointer[types.Header] // Current head of the chain currentSnapBlock atomic.Pointer[types.Header] // Current head of snap-sync currentFinalBlock atomic.Pointer[types.Header] // Latest (consensus) finalized block + chasingHead atomic.Pointer[types.Header] bodyCache *lru.Cache[common.Hash, *types.Body] bodyRLPCache *lru.Cache[common.Hash, rlp.RawValue] receiptsCache *lru.Cache[common.Hash, []*types.Receipt] blockCache *lru.Cache[common.Hash, *types.Block] txLookupCache *lru.Cache[common.Hash, txLookup] + sidecarsCache *lru.Cache[common.Hash, types.BlobSidecars] // future blocks are blocks added for later processing futureBlocks *lru.Cache[common.Hash, *types.Block] @@ -300,6 +303,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis bodyCache: lru.NewCache[common.Hash, *types.Body](bodyCacheLimit), bodyRLPCache: lru.NewCache[common.Hash, rlp.RawValue](bodyCacheLimit), receiptsCache: lru.NewCache[common.Hash, []*types.Receipt](receiptsCacheLimit), + sidecarsCache: lru.NewCache[common.Hash, types.BlobSidecars](sidecarsCacheLimit), blockCache: lru.NewCache[common.Hash, *types.Block](blockCacheLimit), txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit), futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks), @@ -326,6 +330,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis bc.currentBlock.Store(nil) bc.currentSnapBlock.Store(nil) bc.currentFinalBlock.Store(nil) + bc.chasingHead.Store(nil) // Update chain info data metrics chainInfoGauge.Update(metrics.GaugeInfoValue{"chain_id": bc.chainConfig.ChainID.String()}) @@ -806,6 +811,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha bc.bodyCache.Purge() bc.bodyRLPCache.Purge() bc.receiptsCache.Purge() + bc.sidecarsCache.Purge() bc.blockCache.Purge() bc.txLookupCache.Purge() bc.futureBlocks.Purge() @@ -857,6 +863,16 @@ func (bc *BlockChain) SnapSyncCommitHead(hash common.Hash) error { return nil } +// UpdateChasingHead update remote best chain head, used by DA check now. +func (bc *BlockChain) UpdateChasingHead(head *types.Header) { + bc.chasingHead.Store(head) +} + +// ChasingHead return the best chain head of peers. +func (bc *BlockChain) ChasingHead() *types.Header { + return bc.chasingHead.Load() +} + // Reset purges the entire blockchain, restoring it to its genesis state. func (bc *BlockChain) Reset() error { return bc.ResetWithGenesisBlock(bc.genesisBlock) @@ -1131,6 +1147,15 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ } } + // check DA after cancun + lastBlk := blockChain[len(blockChain)-1] + if bc.chainConfig.Oasys != nil && bc.chainConfig.IsCancun(lastBlk.Number(), lastBlk.Time()) { + if _, err := CheckDataAvailableInBatch(bc, blockChain); err != nil { + log.Debug("CheckDataAvailableInBatch", "err", err) + return 0, err + } + } + var ( stats = struct{ processed, ignored int32 }{} start = time.Now() @@ -1269,6 +1294,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ // Write all the data out into the database rawdb.WriteBody(batch, block.Hash(), block.NumberU64(), block.Body()) rawdb.WriteReceipts(batch, block.Hash(), block.NumberU64(), receiptChain[i]) + if bc.chainConfig.IsCancun(block.Number(), block.Time()) { + rawdb.WriteBlobSidecars(batch, block.Hash(), block.NumberU64(), block.Sidecars()) + } // Write everything belongs to the blocks into the database. So that // we can ensure all components of body is completed(body, receipts) @@ -1338,6 +1366,10 @@ func (bc *BlockChain) writeBlockWithoutState(block *types.Block, td *big.Int) (e batch := bc.db.NewBatch() rawdb.WriteTd(batch, block.Hash(), block.NumberU64(), td) rawdb.WriteBlock(batch, block) + // if cancun is enabled, here need to write sidecars too + if bc.chainConfig.IsCancun(block.Number(), block.Time()) { + rawdb.WriteBlobSidecars(batch, block.Hash(), block.NumberU64(), block.Sidecars()) + } if err := batch.Write(); err != nil { log.Crit("Failed to write block into disk", "err", err) } @@ -1377,6 +1409,10 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. rawdb.WriteBlock(blockBatch, block) rawdb.WriteReceipts(blockBatch, block.Hash(), block.NumberU64(), receipts) rawdb.WritePreimages(blockBatch, state.Preimages()) + // if cancun is enabled, here need to write sidecars too + if bc.chainConfig.IsCancun(block.Number(), block.Time()) { + rawdb.WriteBlobSidecars(blockBatch, block.Hash(), block.NumberU64(), block.Sidecars()) + } if err := blockBatch.Write(); err != nil { log.Crit("Failed to write block into disk", "err", err) } @@ -1601,6 +1637,12 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) } } }() + // check block data available first + if bc.chainConfig.Oasys != nil { + if index, err := CheckDataAvailableInBatch(bc, chain); err != nil { + return index, err + } + } // Start the parallel header verifier headers := make([]*types.Header, len(chain)) for i, block := range chain { @@ -2028,6 +2070,9 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i for i := len(hashes) - 1; i >= 0; i-- { // Append the next block to our batch block := bc.GetBlock(hashes[i], numbers[i]) + if block != nil && bc.chainConfig.IsCancun(block.Number(), block.Time()) { + block = block.WithSidecars(bc.GetSidecarsByHash(hashes[i])) + } blocks = append(blocks, block) memory += block.Size() @@ -2100,6 +2145,9 @@ func (bc *BlockChain) recoverAncestors(block *types.Block) (common.Hash, error) } else { b = bc.GetBlock(hashes[i], numbers[i]) } + if bc.chainConfig.IsCancun(b.Number(), b.Time()) { + b = b.WithSidecars(bc.GetSidecarsByHash(b.Hash())) + } if _, err := bc.insertChain(types.Blocks{b}, false); err != nil { return b.ParentHash(), err } diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index b0630f8c4..acb11ac21 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -240,6 +240,23 @@ func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts { return receipts } +// GetSidecarsByHash retrieves the sidecars for all transactions in a given block. +func (bc *BlockChain) GetSidecarsByHash(hash common.Hash) types.BlobSidecars { + if sidecars, ok := bc.sidecarsCache.Get(hash); ok { + return sidecars + } + number := rawdb.ReadHeaderNumber(bc.db, hash) + if number == nil { + return nil + } + sidecars := rawdb.ReadBlobSidecars(bc.db, hash, *number) + if sidecars == nil { + return nil + } + bc.sidecarsCache.Add(hash, sidecars) + return sidecars +} + // GetUnclesInChain retrieves all the uncles from a given block backwards until // a specific distance is reached. func (bc *BlockChain) GetUnclesInChain(block *types.Block, length int) []*types.Header { diff --git a/core/chain_makers.go b/core/chain_makers.go index a6b5568e9..c69421792 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -52,6 +52,9 @@ type BlockGen struct { withdrawals []*types.Withdrawal engine consensus.Engine + + // extra data of block + sidecars types.BlobSidecars } // SetCoinbase sets the coinbase of the generated block. @@ -171,6 +174,11 @@ func (b *BlockGen) AddUncheckedTx(tx *types.Transaction) { b.txs = append(b.txs, tx) } +// AddBlobSidecar add block's blob sidecar for DA checking. +func (b *BlockGen) AddBlobSidecar(sidecar *types.BlobSidecar) { + b.sidecars = append(b.sidecars, sidecar) +} + // Number returns the block number of the block being generated. func (b *BlockGen) Number() *big.Int { return new(big.Int).Set(b.header.Number) @@ -186,6 +194,15 @@ func (b *BlockGen) BaseFee() *big.Int { return new(big.Int).Set(b.header.BaseFee) } +// ExcessBlobGas returns the EIP-4844 ExcessBlobGas of the block. +func (b *BlockGen) ExcessBlobGas() uint64 { + excessBlobGas := b.header.ExcessBlobGas + if excessBlobGas == nil { + return 0 + } + return *excessBlobGas +} + // Gas returns the amount of gas left in the current block. func (b *BlockGen) Gas() uint64 { return b.header.GasLimit - b.header.GasUsed @@ -352,6 +369,13 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if err != nil { panic(err) } + if config.IsCancun(block.Number(), block.Time()) { + for _, s := range b.sidecars { + s.BlockNumber = block.Number() + s.BlockHash = block.Hash() + } + block = block.WithSidecars(b.sidecars) + } // Write state changes to db root, err := statedb.Commit(b.header.Number.Uint64(), config.IsEIP158(b.header.Number)) @@ -451,6 +475,9 @@ func (cm *chainMaker) makeHeader(parent *types.Block, state *state.StateDB, engi excessBlobGas := eip4844.CalcExcessBlobGas(parentExcessBlobGas, parentBlobGasUsed) header.ExcessBlobGas = &excessBlobGas header.BlobGasUsed = new(uint64) + if cm.config.Oasys != nil { + header.WithdrawalsHash = &types.EmptyWithdrawalsHash + } header.ParentBeaconRoot = new(common.Hash) } return header @@ -579,3 +606,7 @@ func (cm *chainMaker) GetTd(hash common.Hash, number uint64) *big.Int { func (cm *chainMaker) GetCanonicalHash(number uint64) common.Hash { return common.Hash{} } + +func (cm *chainMaker) ChasingHead() *types.Header { + panic("not supported") +} diff --git a/core/data_availability.go b/core/data_availability.go new file mode 100644 index 000000000..2953c8c36 --- /dev/null +++ b/core/data_availability.go @@ -0,0 +1,162 @@ +package core + +import ( + "crypto/sha256" + "errors" + "fmt" + "sync" + "time" + + "github.com/ethereum/go-ethereum/metrics" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/gopool" + "github.com/ethereum/go-ethereum/consensus" + "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto/kzg4844" + "github.com/ethereum/go-ethereum/params" +) + +var ( + daCheckTimer = metrics.NewRegisteredTimer("chain/dacheck", nil) +) + +// validateBlobSidecar it is same as validateBlobSidecar in core/txpool/validation.go +func validateBlobSidecar(hashes []common.Hash, sidecar *types.BlobSidecar) error { + if len(sidecar.Blobs) != len(hashes) { + return fmt.Errorf("invalid number of %d blobs compared to %d blob hashes", len(sidecar.Blobs), len(hashes)) + } + if len(sidecar.Commitments) != len(hashes) { + return fmt.Errorf("invalid number of %d blob commitments compared to %d blob hashes", len(sidecar.Commitments), len(hashes)) + } + if len(sidecar.Proofs) != len(hashes) { + return fmt.Errorf("invalid number of %d blob proofs compared to %d blob hashes", len(sidecar.Proofs), len(hashes)) + } + // Blob quantities match up, validate that the provers match with the + // transaction hash before getting to the cryptography + hasher := sha256.New() + for i, vhash := range hashes { + computed := kzg4844.CalcBlobHashV1(hasher, &sidecar.Commitments[i]) + if vhash != computed { + return fmt.Errorf("blob %d: computed hash %#x mismatches transaction one %#x", i, computed, vhash) + } + } + // Blob commitments match with the hashes in the transaction, verify the + // blobs themselves via KZG + for i := range sidecar.Blobs { + if err := kzg4844.VerifyBlobProof(sidecar.Blobs[i], sidecar.Commitments[i], sidecar.Proofs[i]); err != nil { + return fmt.Errorf("invalid blob %d: %v", i, err) + } + } + return nil +} + +// IsDataAvailable it checks that the blobTx block has available blob data +func IsDataAvailable(chain consensus.ChainHeaderReader, block *types.Block) (err error) { + defer func(start time.Time) { + daCheckTimer.Update(time.Since(start)) + }(time.Now()) + + // refer logic in ValidateBody + if !chain.Config().IsCancun(block.Number(), block.Time()) { + if block.Sidecars() != nil { + return errors.New("sidecars present in block body before cancun") + } + return nil + } + + // only required to check within MinBlocksForBlobRequests block's DA + highest := chain.ChasingHead() + current := chain.CurrentHeader() + if highest == nil || highest.Number.Cmp(current.Number) < 0 { + highest = current + } + if block.NumberU64()+params.MinBlocksForBlobRequests < highest.Number.Uint64() { + // if we needn't check DA of this block, just clean it + block.CleanSidecars() + return nil + } + + // if sidecar is nil, just clean it. And it will be used for saving in ancient. + if block.Sidecars() == nil { + block.CleanSidecars() + } + sidecars := block.Sidecars() + for _, s := range sidecars { + if err := s.SanityCheck(block.Number(), block.Hash()); err != nil { + return err + } + } + // alloc block's blobTx + blobTxs := make([]*types.Transaction, 0, len(sidecars)) + blobTxIndexes := make([]uint64, 0, len(sidecars)) + for i, tx := range block.Transactions() { + if tx.Type() != types.BlobTxType { + continue + } + blobTxs = append(blobTxs, tx) + blobTxIndexes = append(blobTxIndexes, uint64(i)) + } + if len(blobTxs) != len(sidecars) { + return fmt.Errorf("blob info mismatch: sidecars %d, versionedHashes:%d", len(sidecars), len(blobTxs)) + } + + // check blob amount + blobCnt := 0 + for _, s := range sidecars { + blobCnt += len(s.Blobs) + } + if blobCnt > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob { + return fmt.Errorf("too many blobs in block: have %d, permitted %d", blobCnt, params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob) + } + + // check blob and versioned hash + for i, tx := range blobTxs { + // check sidecar tx related + if sidecars[i].TxHash != tx.Hash() { + return fmt.Errorf("sidecar's TxHash mismatch with expected transaction, want: %v, have: %v", sidecars[i].TxHash, tx.Hash()) + } + if sidecars[i].TxIndex != blobTxIndexes[i] { + return fmt.Errorf("sidecar's TxIndex mismatch with expected transaction, want: %v, have: %v", sidecars[i].TxIndex, blobTxIndexes[i]) + } + if err := validateBlobSidecar(tx.BlobHashes(), sidecars[i]); err != nil { + return err + } + } + + return nil +} + +func CheckDataAvailableInBatch(chainReader consensus.ChainHeaderReader, chain types.Blocks) (int, error) { + if len(chain) == 1 { + return 0, IsDataAvailable(chainReader, chain[0]) + } + + var ( + wg sync.WaitGroup + errs sync.Map + ) + + for i := range chain { + wg.Add(1) + func(index int, block *types.Block) { + gopool.Submit(func() { + defer wg.Done() + errs.Store(index, IsDataAvailable(chainReader, block)) + }) + }(i, chain[i]) + } + + wg.Wait() + for i := range chain { + val, exist := errs.Load(i) + if !exist || val == nil { + continue + } + err := val.(error) + if err != nil { + return i, err + } + } + return 0, nil +} diff --git a/core/headerchain.go b/core/headerchain.go index a0e2b7921..379b0e517 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -392,6 +392,10 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, start time.Time, return res.status, err } +func (hc *HeaderChain) ChasingHead() *types.Header { + return nil +} + // GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or // a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the // number of blocks to be individually checked before we reach the canonical chain. diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index 4686f82cf..503d94e03 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -376,6 +376,20 @@ func ReadHeader(db ethdb.Reader, hash common.Hash, number uint64) *types.Header return header } +// ReadHeaderAndRaw retrieves the block header corresponding to the hash. +func ReadHeaderAndRaw(db ethdb.Reader, hash common.Hash, number uint64) (*types.Header, rlp.RawValue) { + data := ReadHeaderRLP(db, hash, number) + if len(data) == 0 { + return nil, nil + } + header := new(types.Header) + if err := rlp.DecodeBytes(data, header); err != nil { + log.Error("Invalid block header RLP", "hash", hash, "err", err) + return nil, nil + } + return header, data +} + // WriteHeader stores a block header into the database and also stores the hash- // to-number mapping. func WriteHeader(db ethdb.KeyValueWriter, header *types.Header) { @@ -762,6 +776,48 @@ func WriteBlock(db ethdb.KeyValueWriter, block *types.Block) { WriteHeader(db, block.Header()) } +// WriteAncientBlocksWithBlobs writes entire block data with blobs into ancient store and returns the total written size. +func WriteAncientBlocksWithBlobs(db ethdb.AncientWriter, blocks []*types.Block, receipts []types.Receipts, td *big.Int) (int64, error) { + // find cancun index, it's used for new added blob ancient table + cancunIndex := -1 + for i, block := range blocks { + if block.Sidecars() != nil { + cancunIndex = i + break + } + } + log.Debug("WriteAncientBlocks", "startAt", blocks[0].Number(), "cancunIndex", cancunIndex, "len", len(blocks)) + + var ( + tdSum = new(big.Int).Set(td) + preSize int64 + err error + ) + if cancunIndex > 0 { + preSize, err = WriteAncientBlocks(db, blocks[:cancunIndex], receipts[:cancunIndex], td) + if err != nil { + return preSize, err + } + for i, block := range blocks[:cancunIndex] { + if i > 0 { + tdSum.Add(tdSum, block.Difficulty()) + } + } + tdSum.Add(tdSum, blocks[cancunIndex].Difficulty()) + } + + // It will reset blob ancient table at cancunIndex + if cancunIndex >= 0 { + if err = ResetEmptyBlobAncientTable(db, blocks[cancunIndex].NumberU64()); err != nil { + return 0, err + } + blocks = blocks[cancunIndex:] + receipts = receipts[cancunIndex:] + } + postSize, err := WriteAncientBlocks(db, blocks, receipts, tdSum) + return preSize + postSize, err +} + // WriteAncientBlocks writes entire block data into ancient store and returns the total written size. func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts []types.Receipts, td *big.Int) (int64, error) { var ( @@ -787,6 +843,56 @@ func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts }) } +// ReadBlobSidecarsRLP retrieves all the transaction blobs belonging to a block in RLP encoding. +func ReadBlobSidecarsRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue { + var data []byte + db.ReadAncients(func(reader ethdb.AncientReaderOp) error { + // Check if the data is in ancients + if isCanon(reader, number, hash) { + data, _ = reader.Ancient(ChainFreezerBlobSidecarTable, number) + return nil + } + // If not, try reading from leveldb + data, _ = db.Get(blockBlobSidecarsKey(number, hash)) + return nil + }) + return data +} + +// ReadBlobSidecars retrieves all the transaction blobs belonging to a block. +func ReadBlobSidecars(db ethdb.Reader, hash common.Hash, number uint64) types.BlobSidecars { + data := ReadBlobSidecarsRLP(db, hash, number) + if len(data) == 0 { + return nil + } + var ret types.BlobSidecars + if err := rlp.DecodeBytes(data, &ret); err != nil { + log.Error("Invalid blob array RLP", "hash", hash, "err", err) + return nil + } + return ret +} + +// WriteBlobSidecars stores all the transaction blobs belonging to a block. +// It could input nil for empty blobs. +func WriteBlobSidecars(db ethdb.KeyValueWriter, hash common.Hash, number uint64, blobs types.BlobSidecars) { + data, err := rlp.EncodeToBytes(blobs) + if err != nil { + log.Crit("Failed to encode block blobs", "err", err) + } + // Store the flattened receipt slice + if err := db.Put(blockBlobSidecarsKey(number, hash), data); err != nil { + log.Crit("Failed to store block blobs", "err", err) + } +} + +// DeleteBlobSidecars removes all blob data associated with a block hash. +func DeleteBlobSidecars(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { + if err := db.Delete(blockBlobSidecarsKey(number, hash)); err != nil { + log.Crit("Failed to delete block blobs", "err", err) + } +} + func writeAncientBlock(op ethdb.AncientWriteOp, block *types.Block, header *types.Header, receipts []*types.ReceiptForStorage, td *big.Int) error { num := block.NumberU64() if err := op.AppendRaw(ChainFreezerHashTable, num, block.Hash().Bytes()); err != nil { @@ -804,6 +910,11 @@ func writeAncientBlock(op ethdb.AncientWriteOp, block *types.Block, header *type if err := op.Append(ChainFreezerDifficultyTable, num, td); err != nil { return fmt.Errorf("can't append block %d total difficulty: %v", num, err) } + if block.Sidecars() != nil { + if err := op.Append(ChainFreezerBlobSidecarTable, num, block.Sidecars()); err != nil { + return fmt.Errorf("can't append block %d blobs: %v", num, err) + } + } return nil } @@ -813,6 +924,7 @@ func DeleteBlock(db ethdb.KeyValueWriter, hash common.Hash, number uint64) { DeleteHeader(db, hash, number) DeleteBody(db, hash, number) DeleteTd(db, hash, number) + DeleteBlobSidecars(db, hash, number) // it is safe to delete non-exist blob } // DeleteBlockWithoutNumber removes all block data associated with a hash, except @@ -822,6 +934,7 @@ func DeleteBlockWithoutNumber(db ethdb.KeyValueWriter, hash common.Hash, number deleteHeaderWithoutNumber(db, hash, number) DeleteBody(db, hash, number) DeleteTd(db, hash, number) + DeleteBlobSidecars(db, hash, number) } const badBlockToKeep = 10 diff --git a/core/rawdb/ancient_scheme.go b/core/rawdb/ancient_scheme.go index e88867af0..f1633c6ce 100644 --- a/core/rawdb/ancient_scheme.go +++ b/core/rawdb/ancient_scheme.go @@ -34,18 +34,24 @@ const ( // ChainFreezerDifficultyTable indicates the name of the freezer total difficulty table. ChainFreezerDifficultyTable = "diffs" + + // ChainFreezerBlobSidecarTable indicates the name of the freezer total blob table. + ChainFreezerBlobSidecarTable = "blobs" ) // chainFreezerNoSnappy configures whether compression is disabled for the ancient-tables. // Hashes and difficulties don't compress well. var chainFreezerNoSnappy = map[string]bool{ - ChainFreezerHeaderTable: false, - ChainFreezerHashTable: true, - ChainFreezerBodiesTable: false, - ChainFreezerReceiptTable: false, - ChainFreezerDifficultyTable: true, + ChainFreezerHeaderTable: false, + ChainFreezerHashTable: true, + ChainFreezerBodiesTable: false, + ChainFreezerReceiptTable: false, + ChainFreezerDifficultyTable: true, + ChainFreezerBlobSidecarTable: false, } +var additionTables = []string{ChainFreezerBlobSidecarTable} + const ( // stateHistoryTableSize defines the maximum size of freezer data files. stateHistoryTableSize = 2 * 1000 * 1000 * 1000 diff --git a/core/rawdb/chain_freezer.go b/core/rawdb/chain_freezer.go index bb2c409db..24b4863a6 100644 --- a/core/rawdb/chain_freezer.go +++ b/core/rawdb/chain_freezer.go @@ -17,7 +17,9 @@ package rawdb import ( + "errors" "fmt" + "math/big" "sync" "sync/atomic" "time" @@ -26,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" + "github.com/ethereum/go-ethereum/rlp" ) const ( @@ -39,6 +42,10 @@ const ( freezerBatchLimit = 30000 ) +var ( + missFreezerEnvErr = errors.New("missing freezer env error") +) + // chainFreezer is a wrapper of freezer with additional chain freezing feature. // The background thread will keep moving ancient chain segments from key-value // database to flat files for saving space on live database. @@ -49,6 +56,9 @@ type chainFreezer struct { quit chan struct{} wg sync.WaitGroup trigger chan chan struct{} // Manual blocking freeze trigger, test determinism + + freezeEnv atomic.Value + waitEnvTimes int } // newChainFreezer initializes the freezer for ancient chain data. @@ -156,7 +166,19 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) { if limit-first > freezerBatchLimit { limit = first + freezerBatchLimit } - ancients, err := f.freezeRange(nfdb, first, limit) + + // check env first before chain freeze, it must wait when the env is necessary + if err := f.checkFreezerEnv(); err != nil { + f.waitEnvTimes++ + if f.waitEnvTimes%30 == 0 { + log.Warn("Freezer need related env, may wait for a while, and it's not a issue when non-import block", "err", err) + return + } + backoff = true + continue + } + + ancients, err := f.freezeRangeWithBlobs(nfdb, first, limit) if err != nil { log.Error("Error in block freeze operation", "err", err) backoff = true @@ -243,6 +265,12 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) { } log.Debug("Deep froze chain segment", context...) + env, _ := f.freezeEnv.Load().(*ethdb.FreezerEnv) + // try prune blob data after cancun fork + if isCancun(env, head.Number, head.Time) { + f.tryPruneBlobAncientTable(env, *number) + } + // Avoid database thrashing with tiny writes if frozen-first < freezerBatchLimit { backoff = true @@ -250,9 +278,90 @@ func (f *chainFreezer) freeze(db ethdb.KeyValueStore) { } } +func (f *chainFreezer) tryPruneBlobAncientTable(env *ethdb.FreezerEnv, num uint64) { + extraReserve := getBlobExtraReserveFromEnv(env) + // It means that there is no need for pruning + if extraReserve == 0 { + return + } + reserveThreshold := params.MinBlocksForBlobRequests + extraReserve + if num <= reserveThreshold { + return + } + expectTail := num - reserveThreshold + start := time.Now() + if _, err := f.TruncateTableTail(ChainFreezerBlobSidecarTable, expectTail); err != nil { + log.Error("Cannot prune blob ancient", "block", num, "expectTail", expectTail, "err", err) + return + } + log.Debug("Chain freezer prune useless blobs, now ancient data is", "from", expectTail, "to", num, "cost", common.PrettyDuration(time.Since(start))) +} + +func getBlobExtraReserveFromEnv(env *ethdb.FreezerEnv) uint64 { + if env == nil { + return params.DefaultExtraReserveForBlobRequests + } + return env.BlobExtraReserve +} + +func (f *chainFreezer) freezeRangeWithBlobs(nfdb *nofreezedb, number, limit uint64) (hashes []common.Hash, err error) { + defer func() { + log.Debug("freezeRangeWithBlobs", "from", number, "to", limit, "err", err) + }() + lastHash := ReadCanonicalHash(nfdb, limit) + if lastHash == (common.Hash{}) { + return nil, fmt.Errorf("canonical hash missing, can't freeze block %d", limit) + } + last, _ := ReadHeaderAndRaw(nfdb, lastHash, limit) + if last == nil { + return nil, fmt.Errorf("block header missing, can't freeze block %d", limit) + } + env, _ := f.freezeEnv.Load().(*ethdb.FreezerEnv) + if !isCancun(env, last.Number, last.Time) { + return f.freezeRange(nfdb, number, limit) + } + + var ( + cancunNumber uint64 + preHashes []common.Hash + ) + for i := number; i <= limit; i++ { + hash := ReadCanonicalHash(nfdb, i) + if hash == (common.Hash{}) { + return nil, fmt.Errorf("canonical hash missing, can't freeze block %d", i) + } + h, header := ReadHeaderAndRaw(nfdb, hash, i) + if len(header) == 0 { + return nil, fmt.Errorf("block header missing, can't freeze block %d", i) + } + if isCancun(env, h.Number, h.Time) { + cancunNumber = i + break + } + } + + // freeze pre cancun + preHashes, err = f.freezeRange(nfdb, number, cancunNumber-1) + if err != nil { + return preHashes, err + } + + if err = ResetEmptyBlobAncientTable(f, cancunNumber); err != nil { + return preHashes, err + } + // freeze post cancun + postHashes, err := f.freezeRange(nfdb, cancunNumber, limit) + hashes = append(preHashes, postHashes...) + return hashes, err +} + func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hashes []common.Hash, err error) { - hashes = make([]common.Hash, 0, limit-number) + if number > limit { + return nil, nil + } + env, _ := f.freezeEnv.Load().(*ethdb.FreezerEnv) + hashes = make([]common.Hash, 0, limit-number) _, err = f.ModifyAncients(func(op ethdb.AncientWriteOp) error { for ; number <= limit; number++ { // Retrieve all the components of the canonical block. @@ -260,7 +369,7 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash if hash == (common.Hash{}) { return fmt.Errorf("canonical hash missing, can't freeze block %d", number) } - header := ReadHeaderRLP(nfdb, hash, number) + h, header := ReadHeaderAndRaw(nfdb, hash, number) if len(header) == 0 { return fmt.Errorf("block header missing, can't freeze block %d", number) } @@ -276,6 +385,14 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash if len(td) == 0 { return fmt.Errorf("total difficulty missing, can't freeze block %d", number) } + // blobs is nil before cancun fork + var sidecars rlp.RawValue + if isCancun(env, h.Number, h.Time) { + sidecars = ReadBlobSidecarsRLP(nfdb, hash, number) + if len(sidecars) == 0 { + return fmt.Errorf("block blobs missing, can't freeze block %d", number) + } + } // Write to the batch. if err := op.AppendRaw(ChainFreezerHashTable, number, hash[:]); err != nil { @@ -293,6 +410,11 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash if err := op.AppendRaw(ChainFreezerDifficultyTable, number, td); err != nil { return fmt.Errorf("can't write td to Freezer: %v", err) } + if isCancun(env, h.Number, h.Time) { + if err := op.AppendRaw(ChainFreezerBlobSidecarTable, number, sidecars); err != nil { + return fmt.Errorf("can't write blobs to Freezer: %v", err) + } + } hashes = append(hashes, hash) } @@ -301,3 +423,28 @@ func (f *chainFreezer) freezeRange(nfdb *nofreezedb, number, limit uint64) (hash return hashes, err } + +func (f *chainFreezer) SetupFreezerEnv(env *ethdb.FreezerEnv) error { + f.freezeEnv.Store(env) + return nil +} + +func (f *chainFreezer) checkFreezerEnv() error { + _, exist := f.freezeEnv.Load().(*ethdb.FreezerEnv) + if exist { + return nil + } + return missFreezerEnvErr +} + +func isCancun(env *ethdb.FreezerEnv, num *big.Int, time uint64) bool { + if env == nil || env.ChainCfg == nil { + return false + } + + return env.ChainCfg.IsCancun(num, time) +} + +func ResetEmptyBlobAncientTable(db ethdb.AncientWriter, next uint64) error { + return db.ResetTable(ChainFreezerBlobSidecarTable, next, true) +} diff --git a/core/rawdb/database.go b/core/rawdb/database.go index b4cb4b7a2..1ab1cfa55 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -40,6 +40,7 @@ type freezerdb struct { ancientRoot string ethdb.KeyValueStore ethdb.AncientStore + ethdb.AncientFreezer } // AncientDatadir returns the path of root ancient directory. @@ -83,6 +84,10 @@ func (frdb *freezerdb) Freeze(threshold uint64) error { return nil } +func (frdb *freezerdb) SetupFreezerEnv(env *ethdb.FreezerEnv) error { + return frdb.AncientFreezer.SetupFreezerEnv(env) +} + // nofreezedb is a database wrapper that disables freezer data retrievals. type nofreezedb struct { ethdb.KeyValueStore @@ -133,6 +138,16 @@ func (db *nofreezedb) TruncateTail(items uint64) (uint64, error) { return 0, errNotSupported } +// TruncateTableTail will truncate certain table to new tail +func (db *nofreezedb) TruncateTableTail(kind string, tail uint64) (uint64, error) { + return 0, errNotSupported +} + +// ResetTable will reset certain table with new start point +func (db *nofreezedb) ResetTable(kind string, startAt uint64, onlyEmpty bool) error { + return errNotSupported +} + // Sync returns an error as we don't have a backing chain freezer. func (db *nofreezedb) Sync() error { return errNotSupported @@ -165,6 +180,10 @@ func (db *nofreezedb) AncientDatadir() (string, error) { return "", errNotSupported } +func (db *nofreezedb) SetupFreezerEnv(env *ethdb.FreezerEnv) error { + return nil +} + // NewDatabase creates a high level database on top of a given key-value data // store without a freezer moving immutable chain segments into cold storage. func NewDatabase(db ethdb.KeyValueStore) ethdb.Database { @@ -292,9 +311,10 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace st }() } return &freezerdb{ - ancientRoot: ancient, - KeyValueStore: db, - AncientStore: frdb, + ancientRoot: ancient, + KeyValueStore: db, + AncientStore: frdb, + AncientFreezer: frdb, }, nil } diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index b7824ddc0..d31d81fe3 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -26,6 +26,8 @@ import ( "sync/atomic" "time" + "golang.org/x/exp/slices" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/log" @@ -78,6 +80,7 @@ type Freezer struct { // NewChainFreezer is a small utility method around NewFreezer that sets the // default parameters for the chain storage. +// additionTables indicates the new add tables for freezerDB, it has some special rules. func NewChainFreezer(datadir string, namespace string, readonly bool) (*Freezer, error) { return NewFreezer(datadir, namespace, readonly, freezerTableSize, chainFreezerNoSnappy) } @@ -126,7 +129,15 @@ func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize ui // Create the tables. for name, disableSnappy := range tables { - table, err := newTable(datadir, name, readMeter, writeMeter, sizeGauge, maxTableSize, disableSnappy, readonly) + var ( + table *freezerTable + err error + ) + if slices.Contains(additionTables, name) { + table, err = openAdditionTable(datadir, name, readMeter, writeMeter, sizeGauge, maxTableSize, disableSnappy, readonly) + } else { + table, err = newTable(datadir, name, readMeter, writeMeter, sizeGauge, maxTableSize, disableSnappy, readonly) + } if err != nil { for _, table := range freezer.tables { table.Close() @@ -160,6 +171,20 @@ func NewFreezer(datadir string, namespace string, readonly bool, maxTableSize ui return freezer, nil } +// openAdditionTable create table, it will auto create new files when it was first initialized +func openAdditionTable(datadir, name string, readMeter, writeMeter metrics.Meter, sizeGauge metrics.Gauge, maxTableSize uint32, disableSnappy, readonly bool) (*freezerTable, error) { + if readonly { + f, err := newTable(datadir, name, readMeter, writeMeter, sizeGauge, maxTableSize, disableSnappy, false) + if err != nil { + return nil, err + } + if err = f.Close(); err != nil { + return nil, err + } + } + return newTable(datadir, name, readMeter, writeMeter, sizeGauge, maxTableSize, disableSnappy, readonly) +} + // Close terminates the chain freezer, unmapping all the data files. func (f *Freezer) Close() error { f.writeLock.Lock() @@ -291,8 +316,23 @@ func (f *Freezer) TruncateHead(items uint64) (uint64, error) { if oitems <= items { return oitems, nil } - for _, table := range f.tables { - if err := table.truncateHead(items); err != nil { + for kind, table := range f.tables { + err := table.truncateHead(items) + if err == errTruncationBelowTail { + // This often happens in chain rewinds, but the blob table is special. + // It has the same head, but a different tail from other tables (like bodies, receipts). + // So if the chain is rewound to head below the blob's tail, it needs to reset again. + if kind != ChainFreezerBlobSidecarTable { + return 0, err + } + nt, err := table.resetItems(items) + if err != nil { + return 0, err + } + f.tables[kind] = nt + continue + } + if err != nil { return 0, err } } @@ -348,6 +388,10 @@ 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(additionTables, kind) { + continue + } head = table.items.Load() tail = table.itemHidden.Load() name = kind @@ -355,6 +399,21 @@ 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(additionTables, kind) { + // if the table is empty, just skip + if EmptyTable(table) { + continue + } + // otherwise, just align head + if head != table.items.Load() { + return fmt.Errorf("freezer tables %s and %s have differing head: %d != %d", kind, name, table.items.Load(), head) + } + if tail > table.itemHidden.Load() { + return fmt.Errorf("freezer tables %s and %s have differing tail: %d != %d", kind, name, table.itemHidden.Load(), tail) + } + continue + } if head != table.items.Load() { return fmt.Errorf("freezer tables %s and %s have differing head: %d != %d", kind, name, table.items.Load(), head) } @@ -373,7 +432,18 @@ func (f *Freezer) repair() error { head = uint64(math.MaxUint64) tail = uint64(0) ) - for _, table := range f.tables { + for kind, table := range f.tables { + // addition tables only align head + if slices.Contains(additionTables, kind) { + if EmptyTable(table) { + continue + } + items := table.items.Load() + if head > items { + head = items + } + continue + } items := table.items.Load() if head > items { head = items @@ -383,8 +453,27 @@ func (f *Freezer) repair() error { tail = hidden } } - for _, table := range f.tables { - if err := table.truncateHead(head); err != nil { + for kind, table := range f.tables { + // try to align with exist tables, skip empty table + if slices.Contains(additionTables, kind) && EmptyTable(table) { + continue + } + err := table.truncateHead(head) + if err == errTruncationBelowTail { + // This often happens in chain rewinds, but the blob table is special. + // It has the same head, but a different tail from other tables (like bodies, receipts). + // So if the chain is rewound to head below the blob's tail, it needs to reset again. + if kind != ChainFreezerBlobSidecarTable { + return err + } + nt, err := table.resetItems(head) + if err != nil { + return err + } + f.tables[kind] = nt + continue + } + if err != nil { return err } if err := table.truncateTail(tail); err != nil { @@ -507,3 +596,73 @@ func (f *Freezer) MigrateTable(kind string, convert convertLegacyFn) error { } return nil } + +// TruncateTableTail will truncate certain table to new tail +func (f *Freezer) TruncateTableTail(kind string, tail uint64) (uint64, error) { + if f.readonly { + return 0, errReadOnly + } + + f.writeLock.Lock() + defer f.writeLock.Unlock() + + if !slices.Contains(additionTables, kind) { + return 0, errors.New("only new added table could be truncated independently") + } + t, exist := f.tables[kind] + if !exist { + return 0, errors.New("you reset a non-exist table") + } + + old := t.itemHidden.Load() + if err := t.truncateTail(tail); err != nil { + return 0, err + } + return old, nil +} + +// ResetTable will reset certain table with new start point +// only used for ChainFreezerBlobSidecarTable now +func (f *Freezer) ResetTable(kind string, startAt uint64, onlyEmpty bool) error { + if f.readonly { + return errReadOnly + } + + f.writeLock.Lock() + defer f.writeLock.Unlock() + + t, exist := f.tables[kind] + if !exist { + return errors.New("you reset a non-exist table") + } + + // if you reset a non empty table just skip + if onlyEmpty && !EmptyTable(t) { + return nil + } + + if err := f.Sync(); err != nil { + return err + } + nt, err := t.resetItems(startAt) + if err != nil { + return err + } + f.tables[kind] = nt + + // repair all tables with same tail & head + if err := f.repair(); err != nil { + for _, table := range f.tables { + table.Close() + } + return err + } + + f.writeBatch = newFreezerBatch(f) + log.Debug("Reset Table", "kind", kind, "tail", f.tables[kind].itemHidden.Load(), "frozen", f.tables[kind].items.Load()) + return nil +} + +func EmptyTable(t *freezerTable) bool { + return t.items.Load() == 0 +} diff --git a/core/rawdb/freezer_batch.go b/core/rawdb/freezer_batch.go index 84a63a451..3ed823909 100644 --- a/core/rawdb/freezer_batch.go +++ b/core/rawdb/freezer_batch.go @@ -19,6 +19,8 @@ package rawdb import ( "fmt" + "golang.org/x/exp/slices" + "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/rlp" "github.com/golang/snappy" @@ -64,6 +66,10 @@ func (batch *freezerBatch) commit() (item uint64, writeSize int64, err error) { // Check that count agrees on all batches. item = uint64(math.MaxUint64) for name, tb := range batch.tables { + // skip empty addition tables + if slices.Contains(additionTables, name) && EmptyTable(tb.t) { + continue + } if item < math.MaxUint64 && tb.curItem != item { return 0, 0, fmt.Errorf("table %s is at item %d, want %d", name, tb.curItem, item) } diff --git a/core/rawdb/freezer_resettable.go b/core/rawdb/freezer_resettable.go index 7a8548973..3413ca52b 100644 --- a/core/rawdb/freezer_resettable.go +++ b/core/rawdb/freezer_resettable.go @@ -171,6 +171,22 @@ func (f *ResettableFreezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) return f.freezer.ModifyAncients(fn) } +// TruncateTableTail will truncate certain table to new tail +func (f *ResettableFreezer) TruncateTableTail(kind string, tail uint64) (uint64, error) { + f.lock.RLock() + defer f.lock.RUnlock() + + return f.freezer.TruncateTableTail(kind, tail) +} + +// ResetTable will reset certain table with new start point +func (f *ResettableFreezer) ResetTable(kind string, startAt uint64, onlyEmpty bool) error { + f.lock.RLock() + defer f.lock.RUnlock() + + return f.freezer.ResetTable(kind, startAt, onlyEmpty) +} + // TruncateHead discards any recent data above the provided threshold number. // It returns the previous head number. func (f *ResettableFreezer) TruncateHead(items uint64) (uint64, error) { diff --git a/core/rawdb/freezer_table.go b/core/rawdb/freezer_table.go index 4b9d510e8..75e40859b 100644 --- a/core/rawdb/freezer_table.go +++ b/core/rawdb/freezer_table.go @@ -44,6 +44,8 @@ var ( // errNotSupported is returned if the database doesn't support the required operation. errNotSupported = errors.New("this operation is not supported") + + errTruncationBelowTail = errors.New("truncation below tail") ) // indexEntry contains the number/id of the file that the data resides in, as well as the @@ -398,7 +400,7 @@ func (t *freezerTable) truncateHead(items uint64) error { return nil } if items < t.itemHidden.Load() { - return errors.New("truncation below tail") + return errTruncationBelowTail } // We need to truncate, save the old size for metrics tracking oldSize, err := t.sizeNolock() @@ -988,3 +990,54 @@ func (t *freezerTable) dumpIndex(w io.Writer, start, stop int64) { } fmt.Fprintf(w, "|--------------------------|\n") } + +// resetItems reset freezer table to 0 items with new startAt +// only used for ChainFreezerBlobSidecarTable now +func (t *freezerTable) resetItems(startAt uint64) (*freezerTable, error) { + t.lock.Lock() + defer t.lock.Unlock() + if t.readonly { + return nil, errors.New("resetItems in readonly mode") + } + + // remove all data files + t.head.Close() + t.releaseFilesAfter(0, true) + t.releaseFile(0) + + // overwrite metadata file + if err := writeMetadata(t.meta, newMetadata(startAt)); err != nil { + return nil, err + } + if err := t.meta.Sync(); err != nil { + return nil, err + } + t.meta.Close() + + // recreate the index file + t.index.Close() + os.Remove(t.index.Name()) + var idxName string + if t.noCompression { + idxName = fmt.Sprintf("%s.ridx", t.name) // raw index file + } else { + idxName = fmt.Sprintf("%s.cidx", t.name) // compressed index file + } + index, err := openFreezerFileForAppend(filepath.Join(t.path, idxName)) + if err != nil { + return nil, err + } + tailIndex := indexEntry{ + filenum: 0, + offset: uint32(startAt), + } + if _, err = index.Write(tailIndex.append(nil)); err != nil { + return nil, err + } + if err := index.Sync(); err != nil { + return nil, err + } + index.Close() + + return newFreezerTable(t.path, t.name, t.noCompression, t.readonly) +} diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index a5fb3cc33..87e280484 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -133,8 +133,9 @@ var ( BloomTrieIndexPrefix = []byte("bltIndex-") CliqueSnapshotPrefix = []byte("clique-") + OasysSnapshotPrefix = []byte("oasys-") - OasysSnapshotPrefix = []byte("oasys-") + BlockBlobSidecarsPrefix = []byte("blobs") BestUpdateKey = []byte("update-") // bigEndian64(syncPeriod) -> RLP(types.LightClientUpdate) (nextCommittee only referenced by root hash) FixedCommitteeRootKey = []byte("fixedRoot-") // bigEndian64(syncPeriod) -> committee root hash @@ -194,6 +195,11 @@ func blockReceiptsKey(number uint64, hash common.Hash) []byte { return append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...) } +// blockBlobSidecarsKey = BlockBlobSidecarsPrefix + blockNumber (uint64 big endian) + blockHash +func blockBlobSidecarsKey(number uint64, hash common.Hash) []byte { + return append(append(BlockBlobSidecarsPrefix, encodeBlockNumber(number)...), hash.Bytes()...) +} + // txLookupKey = txLookupPrefix + hash func txLookupKey(hash common.Hash) []byte { return append(txLookupPrefix, hash.Bytes()...) diff --git a/core/rawdb/table.go b/core/rawdb/table.go index 19e4ed5b5..ff5de4d99 100644 --- a/core/rawdb/table.go +++ b/core/rawdb/table.go @@ -91,6 +91,16 @@ func (t *table) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (int64, erro return t.db.ModifyAncients(fn) } +// TruncateTableTail will truncate certain table to new tail +func (t *table) TruncateTableTail(kind string, tail uint64) (uint64, error) { + return t.db.TruncateTableTail(kind, tail) +} + +// ResetTable will reset certain table with new start point +func (t *table) ResetTable(kind string, startAt uint64, onlyEmpty bool) error { + return t.db.ResetTable(kind, startAt, onlyEmpty) +} + func (t *table) ReadAncients(fn func(reader ethdb.AncientReaderOp) error) (err error) { return t.db.ReadAncients(fn) } @@ -207,6 +217,10 @@ func (t *table) NewSnapshot() (ethdb.Snapshot, error) { return t.db.NewSnapshot() } +func (t *table) SetupFreezerEnv(env *ethdb.FreezerEnv) error { + return nil +} + // tableBatch is a wrapper around a database batch that prefixes each key access // with a pre-configured string. type tableBatch struct { diff --git a/core/state_transition.go b/core/state_transition.go index 9c4f76d1c..934f172e8 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -457,6 +457,13 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { fee := new(uint256.Int).SetUint64(st.gasUsed()) fee.Mul(fee, effectiveTipU256) st.state.AddBalance(st.evm.Context.Coinbase, fee) + if st.evm.ChainConfig().Oasys != nil && rules.IsCancun { + // add extra blob fee reward + blobFee := new(big.Int).SetUint64(st.blobGasUsed()) + blobFee.Mul(blobFee, st.evm.Context.BlobBaseFee) + blobFeeU256, _ := uint256.FromBig(blobFee) + st.state.AddBalance(st.evm.Context.Coinbase, blobFeeU256) + } } return &ExecutionResult{ diff --git a/core/types/blob_sidecar.go b/core/types/blob_sidecar.go new file mode 100644 index 000000000..a97d1ed40 --- /dev/null +++ b/core/types/blob_sidecar.go @@ -0,0 +1,94 @@ +package types + +import ( + "bytes" + "encoding/json" + "errors" + "math/big" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/ethereum/go-ethereum/rlp" +) + +type BlobSidecars []*BlobSidecar + +// Len returns the length of s. +func (s BlobSidecars) Len() int { return len(s) } + +// EncodeIndex encodes the i'th BlobTxSidecar to w. Note that this does not check for errors +// because we assume that BlobSidecars will only ever contain valid sidecars +func (s BlobSidecars) EncodeIndex(i int, w *bytes.Buffer) { + rlp.Encode(w, s[i]) +} + +type BlobSidecar struct { + BlobTxSidecar + BlockNumber *big.Int `json:"blockNumber"` + BlockHash common.Hash `json:"blockHash"` + TxIndex uint64 `json:"transactionIndex"` + TxHash common.Hash `json:"transactionHash"` +} + +func NewBlobSidecarFromTx(tx *Transaction) *BlobSidecar { + if tx.BlobTxSidecar() == nil { + return nil + } + return &BlobSidecar{ + BlobTxSidecar: *tx.BlobTxSidecar(), + TxHash: tx.Hash(), + } +} + +func (s *BlobSidecar) SanityCheck(blockNumber *big.Int, blockHash common.Hash) error { + if s.BlockNumber.Cmp(blockNumber) != 0 { + return errors.New("BlobSidecar with wrong block number") + } + if s.BlockHash != blockHash { + return errors.New("BlobSidecar with wrong block hash") + } + if len(s.Blobs) != len(s.Commitments) { + return errors.New("BlobSidecar has wrong commitment length") + } + if len(s.Blobs) != len(s.Proofs) { + return errors.New("BlobSidecar has wrong proof length") + } + return nil +} + +func (s *BlobSidecar) MarshalJSON() ([]byte, error) { + fields := map[string]interface{}{ + "blockHash": s.BlockHash, + "blockNumber": hexutil.EncodeUint64(s.BlockNumber.Uint64()), + "txHash": s.TxHash, + "txIndex": hexutil.EncodeUint64(s.TxIndex), + } + fields["blobSidecar"] = s.BlobTxSidecar + return json.Marshal(fields) +} + +func (s *BlobSidecar) UnmarshalJSON(input []byte) error { + type blobSidecar struct { + BlobSidecar BlobTxSidecar `json:"blobSidecar"` + BlockNumber *hexutil.Big `json:"blockNumber"` + BlockHash common.Hash `json:"blockHash"` + TxIndex *hexutil.Big `json:"txIndex"` + TxHash common.Hash `json:"txHash"` + } + var blob blobSidecar + if err := json.Unmarshal(input, &blob); err != nil { + return err + } + s.BlobTxSidecar = blob.BlobSidecar + if blob.BlockNumber == nil { + return errors.New("missing required field 'blockNumber' for BlobSidecar") + } + s.BlockNumber = blob.BlockNumber.ToInt() + s.BlockHash = blob.BlockHash + if blob.TxIndex == nil { + return errors.New("missing required field 'txIndex' for BlobSidecar") + } + s.TxIndex = blob.TxIndex.ToInt().Uint64() + s.TxHash = blob.TxHash + return nil +} diff --git a/core/types/block.go b/core/types/block.go index 4870802bf..a01fa225b 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -166,6 +166,11 @@ func (h *Header) EmptyReceipts() bool { return h.ReceiptHash == EmptyReceiptsHash } +// EmptyWithdrawalsHash returns true if the WithdrawalsHash is EmptyWithdrawalsHash. +func (h *Header) EmptyWithdrawalsHash() bool { + return h.WithdrawalsHash != nil && *h.WithdrawalsHash == EmptyWithdrawalsHash +} + // Body is a simple (mutable, non-safe) data container for storing and moving // a block's data contents (transactions and uncles) together. type Body struct { @@ -205,6 +210,9 @@ type Block struct { // inter-peer block relay. ReceivedAt time.Time ReceivedFrom interface{} + + // sidecars provides DA check + sidecars BlobSidecars } // "external" block encoding. used for eth protocol, etc. @@ -422,6 +430,14 @@ func (b *Block) SanityCheck() error { return b.header.SanityCheck() } +func (b *Block) Sidecars() BlobSidecars { + return b.sidecars +} + +func (b *Block) CleanSidecars() { + b.sidecars = make(BlobSidecars, 0) +} + type writeCounter uint64 func (c *writeCounter) Write(b []byte) (int, error) { @@ -446,11 +462,17 @@ func NewBlockWithHeader(header *Header) *Block { // WithSeal returns a new block with the data from b but the header replaced with // the sealed one. func (b *Block) WithSeal(header *Header) *Block { + // fill sidecars metadata + for _, sidecar := range b.sidecars { + sidecar.BlockNumber = header.Number + sidecar.BlockHash = header.Hash() + } return &Block{ header: CopyHeader(header), transactions: b.transactions, uncles: b.uncles, withdrawals: b.withdrawals, + sidecars: b.sidecars, } } @@ -461,6 +483,7 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block { transactions: make([]*Transaction, len(transactions)), uncles: make([]*Header, len(uncles)), withdrawals: b.withdrawals, + sidecars: b.sidecars, } copy(block.transactions, transactions) for i := range uncles { @@ -475,6 +498,7 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block { header: b.header, transactions: b.transactions, uncles: b.uncles, + sidecars: b.sidecars, } if withdrawals != nil { block.withdrawals = make([]*Withdrawal, len(withdrawals)) @@ -483,6 +507,21 @@ func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block { return block } +// WithSidecars returns a block containing the given blobs. +func (b *Block) WithSidecars(sidecars BlobSidecars) *Block { + block := &Block{ + header: b.header, + transactions: b.transactions, + uncles: b.uncles, + withdrawals: b.withdrawals, + } + if sidecars != nil { + block.sidecars = make(BlobSidecars, len(sidecars)) + copy(block.sidecars, sidecars) + } + return block +} + // Hash returns the keccak256 hash of b's header. // The hash is computed on the first call and cached thereafter. func (b *Block) Hash() common.Hash { diff --git a/core/types/tx_blob.go b/core/types/tx_blob.go index 25a85695e..158d76e6f 100644 --- a/core/types/tx_blob.go +++ b/core/types/tx_blob.go @@ -54,9 +54,9 @@ type BlobTx struct { // BlobTxSidecar contains the blobs of a blob transaction. type BlobTxSidecar struct { - Blobs []kzg4844.Blob // Blobs needed by the blob pool - Commitments []kzg4844.Commitment // Commitments needed by the blob pool - Proofs []kzg4844.Proof // Proofs needed by the blob pool + Blobs []kzg4844.Blob `json:"blobs"` // Blobs needed by the blob pool + Commitments []kzg4844.Commitment `json:"commitments"` // Commitments needed by the blob pool + Proofs []kzg4844.Proof `json:"proofs"` // Proofs needed by the blob pool } // BlobHashes computes the blob hashes of the given blobs. diff --git a/eth/api_backend.go b/eth/api_backend.go index 6eeec78ce..6a8f32957 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -238,6 +238,10 @@ func (b *EthAPIBackend) GetReceipts(ctx context.Context, hash common.Hash) (type return b.eth.blockchain.GetReceiptsByHash(hash), nil } +func (b *EthAPIBackend) GetBlobSidecars(ctx context.Context, hash common.Hash) (types.BlobSidecars, error) { + return b.eth.blockchain.GetSidecarsByHash(hash), nil +} + func (b *EthAPIBackend) GetLogs(ctx context.Context, hash common.Hash, number uint64) ([][]*types.Log, error) { return rawdb.ReadLogs(b.eth.chainDb, hash, number), nil } diff --git a/eth/backend.go b/eth/backend.go index efcc3e07e..c4e367c93 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -153,6 +153,13 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if err != nil { return nil, err } + // startup ancient freeze + if err = chainDb.SetupFreezerEnv(ðdb.FreezerEnv{ + ChainCfg: chainConfig, + BlobExtraReserve: config.BlobExtraReserve, + }); err != nil { + return nil, err + } networkID := config.NetworkId if networkID == 0 { networkID = chainConfig.ChainID.Uint64() diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index cc1258ca5..95681b9da 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -1548,11 +1548,13 @@ func TestBlockToPayloadWithBlobs(t *testing.T) { } txs = append(txs, types.NewTx(&inner)) - sidecars := []*types.BlobTxSidecar{ + sidecars := []*types.BlobSidecar{ { - Blobs: make([]kzg4844.Blob, 1), - Commitments: make([]kzg4844.Commitment, 1), - Proofs: make([]kzg4844.Proof, 1), + BlobTxSidecar: types.BlobTxSidecar{ + Blobs: make([]kzg4844.Blob, 1), + Commitments: make([]kzg4844.Commitment, 1), + Proofs: make([]kzg4844.Proof, 1), + }, }, } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 57cb41bcc..656deded4 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -48,7 +48,7 @@ var ( maxQueuedHeaders = 32 * 1024 // [eth/62] Maximum number of headers to queue for import (DOS protection) maxHeadersProcess = 2048 // Number of header download results to import at once into the chain maxResultsProcess = 2048 // Number of content download results to import at once into the chain - fullMaxForkAncestry uint64 = params.FullImmutabilityThreshold // Maximum chain reorganisation (locally redeclared so tests can reduce it) + FullMaxForkAncestry uint64 = params.FullImmutabilityThreshold // Maximum chain reorganisation (locally redeclared so tests can reduce it) lightMaxForkAncestry uint64 = params.LightImmutabilityThreshold // Maximum chain reorganisation (locally redeclared so tests can reduce it) reorgProtThreshold = 48 // Threshold number of recent blocks to disable mini reorg protection @@ -214,6 +214,9 @@ type BlockChain interface { // TrieDB retrieves the low level trie database used for interacting // with trie nodes. TrieDB() *triedb.Database + + // UpdateChasingHead update remote best chain head, used by DA check now. + UpdateChasingHead(head *types.Header) } // New creates a new downloader to fetch hashes and blocks from remote peers. @@ -589,16 +592,16 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd * // or a reasonable height if no finalized block is yet announced. if final != nil { d.ancientLimit = final.Number.Uint64() - } else if height > fullMaxForkAncestry+1 { - d.ancientLimit = height - fullMaxForkAncestry - 1 + } else if height > FullMaxForkAncestry+1 { + d.ancientLimit = height - FullMaxForkAncestry - 1 } else { d.ancientLimit = 0 } } else { // Legacy sync, use the best announcement we have from the remote peer. // TODO(karalabe): Drop this pathway. - if height > fullMaxForkAncestry+1 { - d.ancientLimit = height - fullMaxForkAncestry - 1 + if height > FullMaxForkAncestry+1 { + d.ancientLimit = height - FullMaxForkAncestry - 1 } else { d.ancientLimit = 0 } @@ -649,6 +652,8 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, td, ttd * } else if mode == FullSync { fetchers = append(fetchers, func() error { return d.processFullSyncContent(ttd, beaconMode) }) } + // update the chasing head + d.blockchain.UpdateChasingHead(latest) return d.spawnSync(fetchers) } @@ -844,7 +849,7 @@ func (d *Downloader) findAncestor(p *peerConnection, remoteHeader *types.Header) p.log.Debug("Looking for common ancestor", "local", localHeight, "remote", remoteHeight) // Recap floor value for binary search - maxForkAncestry := fullMaxForkAncestry + maxForkAncestry := FullMaxForkAncestry if d.getMode() == LightSync { maxForkAncestry = lightMaxForkAncestry } @@ -1507,7 +1512,7 @@ func (d *Downloader) importBlockResults(results []*fetchResult) error { ) blocks := make([]*types.Block, len(results)) for i, result := range results { - blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles).WithWithdrawals(result.Withdrawals) + blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles).WithWithdrawals(result.Withdrawals).WithSidecars(result.Sidecars) } // Downloaded blocks are always regarded as trusted after the // transition. Because the downloaded chain is guided by the @@ -1725,7 +1730,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state blocks := make([]*types.Block, len(results)) receipts := make([]types.Receipts, len(results)) for i, result := range results { - blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles).WithWithdrawals(result.Withdrawals) + blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles).WithWithdrawals(result.Withdrawals).WithSidecars(result.Sidecars) receipts[i] = result.Receipts } if index, err := d.blockchain.InsertReceiptChain(blocks, receipts, d.ancientLimit); err != nil { @@ -1736,7 +1741,7 @@ func (d *Downloader) commitSnapSyncData(results []*fetchResult, stateSync *state } func (d *Downloader) commitPivotBlock(result *fetchResult) error { - block := types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles).WithWithdrawals(result.Withdrawals) + block := types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles).WithWithdrawals(result.Withdrawals).WithSidecars(result.Sidecars) log.Debug("Committing snap sync pivot as new head", "number", block.Number(), "hash", block.Hash()) // Commit the pivot block as the new head, will require full sync from here on diff --git a/eth/downloader/fetchers_concurrent_bodies.go b/eth/downloader/fetchers_concurrent_bodies.go index 5105fda66..49f3644fd 100644 --- a/eth/downloader/fetchers_concurrent_bodies.go +++ b/eth/downloader/fetchers_concurrent_bodies.go @@ -89,10 +89,10 @@ func (q *bodyQueue) request(peer *peerConnection, req *fetchRequest, resCh chan // deliver is responsible for taking a generic response packet from the concurrent // fetcher, unpacking the body data and delivering it to the downloader's queue. func (q *bodyQueue) deliver(peer *peerConnection, packet *eth.Response) (int, error) { - txs, uncles, withdrawals := packet.Res.(*eth.BlockBodiesResponse).Unpack() + txs, uncles, withdrawals, sidecars := packet.Res.(*eth.BlockBodiesResponse).Unpack() hashsets := packet.Meta.([][]common.Hash) // {txs hashes, uncle hashes, withdrawal hashes} - accepted, err := q.queue.DeliverBodies(peer.id, txs, hashsets[0], uncles, hashsets[1], withdrawals, hashsets[2]) + accepted, err := q.queue.DeliverBodies(peer.id, txs, hashsets[0], uncles, hashsets[1], withdrawals, hashsets[2], sidecars) switch { case err == nil && len(txs) == 0: peer.log.Trace("Requested bodies delivered") diff --git a/eth/downloader/queue.go b/eth/downloader/queue.go index 6ff858d75..fd26297d7 100644 --- a/eth/downloader/queue.go +++ b/eth/downloader/queue.go @@ -70,6 +70,7 @@ type fetchResult struct { Transactions types.Transactions Receipts types.Receipts Withdrawals types.Withdrawals + Sidecars types.BlobSidecars } func newFetchResult(header *types.Header, fastSync bool) *fetchResult { @@ -774,7 +775,7 @@ func (q *queue) DeliverHeaders(id string, headers []*types.Header, hashes []comm // also wakes any threads waiting for data delivery. func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListHashes []common.Hash, uncleLists [][]*types.Header, uncleListHashes []common.Hash, - withdrawalLists [][]*types.Withdrawal, withdrawalListHashes []common.Hash) (int, error) { + withdrawalLists [][]*types.Withdrawal, withdrawalListHashes []common.Hash, sidecars []types.BlobSidecars) (int, error) { q.lock.Lock() defer q.lock.Unlock() @@ -824,11 +825,21 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH if want := *header.BlobGasUsed / params.BlobTxBlobGasPerBlob; uint64(blobs) != want { // div because the header is surely good vs the body might be bloated return errInvalidBody } + if blobs > params.MaxBlobGasPerBlock/params.BlobTxBlobGasPerBlob { + return errInvalidBody + } } else { if blobs != 0 { return errInvalidBody } } + + // do some sanity check for sidecar + for _, sidecar := range sidecars[index] { + if err := sidecar.SanityCheck(header.Number, header.Hash()); err != nil { + return err + } + } return nil } @@ -836,6 +847,7 @@ func (q *queue) DeliverBodies(id string, txLists [][]*types.Transaction, txListH result.Transactions = txLists[index] result.Uncles = uncleLists[index] result.Withdrawals = withdrawalLists[index] + result.Sidecars = sidecars[index] result.SetBodyDone() } return q.deliver(id, q.blockTaskPool, q.blockTaskQueue, q.blockPendPool, diff --git a/eth/downloader/queue_test.go b/eth/downloader/queue_test.go index 50b9031a2..c10483b5b 100644 --- a/eth/downloader/queue_test.go +++ b/eth/downloader/queue_test.go @@ -341,7 +341,7 @@ func XTestDelivery(t *testing.T) { uncleHashes[i] = types.CalcUncleHash(uncles) } time.Sleep(100 * time.Millisecond) - _, err := q.DeliverBodies(peer.id, txset, txsHashes, uncleset, uncleHashes, nil, nil) + _, err := q.DeliverBodies(peer.id, txset, txsHashes, uncleset, uncleHashes, nil, nil, nil) if err != nil { fmt.Printf("delivered %d bodies %v\n", len(txset), err) } diff --git a/eth/downloader/testchain_test.go b/eth/downloader/testchain_test.go index 46f3febd8..52a8cedf0 100644 --- a/eth/downloader/testchain_test.go +++ b/eth/downloader/testchain_test.go @@ -57,7 +57,7 @@ var pregenerated bool func init() { // Reduce some of the parameters to make the tester faster - fullMaxForkAncestry = 10000 + FullMaxForkAncestry = 10000 lightMaxForkAncestry = 10000 blockCacheMaxItems = 1024 fsHeaderSafetyNet = 256 @@ -65,7 +65,7 @@ func init() { testChainBase = newTestChain(blockCacheMaxItems+200, testGenesis) - var forkLen = int(fullMaxForkAncestry + 50) + var forkLen = int(FullMaxForkAncestry + 50) var wg sync.WaitGroup // Generate the test chains to seed the peers with diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index b77d13e7c..49bc35072 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -68,7 +68,8 @@ var Defaults = Config{ RPCGasCap: 50000000, RPCEVMTimeout: 5 * time.Second, GPO: FullNodeGPO, - RPCTxFeeCap: 1, // 1 ether + RPCTxFeeCap: 1, // 1 ether + BlobExtraReserve: params.DefaultExtraReserveForBlobRequests, // Extra reserve threshold for blob, blob never expires when -1 is set, default 28800 } //go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go @@ -161,6 +162,9 @@ type Config struct { // OverrideVerkle (TODO: remove after the fork) OverrideVerkle *uint64 `toml:",omitempty"` + + // blob setting + BlobExtraReserve uint64 } // CreateConsensusEngine creates a consensus engine for the given chain config. diff --git a/eth/fetcher/block_fetcher.go b/eth/fetcher/block_fetcher.go index 4c4ee0cba..a07df7b3e 100644 --- a/eth/fetcher/block_fetcher.go +++ b/eth/fetcher/block_fetcher.go @@ -122,12 +122,13 @@ type headerFilterTask struct { time time.Time // Arrival time of the headers } -// bodyFilterTask represents a batch of block bodies (transactions and uncles) +// bodyFilterTask represents a batch of block bodies (transactions, sidecars and uncles) // needing fetcher filtering. type bodyFilterTask struct { peer string // The source peer of block bodies transactions [][]*types.Transaction // Collection of transactions per block bodies uncles [][]*types.Header // Collection of uncles per block bodies + sidecars []types.BlobSidecars // Collection of sidecars per block bodies time time.Time // Arrival time of the blocks' contents } @@ -309,7 +310,7 @@ func (f *BlockFetcher) FilterHeaders(peer string, headers []*types.Header, time // FilterBodies extracts all the block bodies that were explicitly requested by // the fetcher, returning those that should be handled differently. -func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, time time.Time) ([][]*types.Transaction, [][]*types.Header) { +func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transaction, uncles [][]*types.Header, sidecars []types.BlobSidecars, time time.Time) ([][]*types.Transaction, [][]*types.Header, []types.BlobSidecars) { log.Trace("Filtering bodies", "peer", peer, "txs", len(transactions), "uncles", len(uncles)) // Send the filter channel to the fetcher @@ -318,20 +319,20 @@ func (f *BlockFetcher) FilterBodies(peer string, transactions [][]*types.Transac select { case f.bodyFilter <- filter: case <-f.quit: - return nil, nil + return nil, nil, nil } // Request the filtering of the body list select { - case filter <- &bodyFilterTask{peer: peer, transactions: transactions, uncles: uncles, time: time}: + case filter <- &bodyFilterTask{peer: peer, transactions: transactions, uncles: uncles, sidecars: sidecars, time: time}: case <-f.quit: - return nil, nil + return nil, nil, nil } // Retrieve the bodies remaining after filtering select { case task := <-filter: - return task.transactions, task.uncles + return task.transactions, task.uncles, task.sidecars case <-f.quit: - return nil, nil + return nil, nil, nil } } @@ -555,8 +556,8 @@ func (f *BlockFetcher) loop() { case res := <-resCh: res.Done <- nil // Ignoring withdrawals here, since the block fetcher is not used post-merge. - txs, uncles, _ := res.Res.(*eth.BlockBodiesResponse).Unpack() - f.FilterBodies(peer, txs, uncles, time.Now()) + txs, uncles, _, sidecars := res.Res.(*eth.BlockBodiesResponse).Unpack() + f.FilterBodies(peer, txs, uncles, sidecars, time.Now()) case <-timeout.C: // The peer didn't respond in time. The request @@ -674,7 +675,7 @@ func (f *BlockFetcher) loop() { blocks := []*types.Block{} // abort early if there's nothing explicitly requested if len(f.completing) > 0 { - for i := 0; i < len(task.transactions) && i < len(task.uncles); i++ { + for i := 0; i < len(task.transactions) && i < len(task.uncles) && i < len(task.sidecars); i++ { // Match up a body to any possible completion request var ( matched = false @@ -701,6 +702,7 @@ func (f *BlockFetcher) loop() { matched = true if f.getBlock(hash) == nil { block := types.NewBlockWithHeader(announce.header).WithBody(task.transactions[i], task.uncles[i]) + block = block.WithSidecars(task.sidecars[i]) block.ReceivedAt = task.time blocks = append(blocks, block) } else { @@ -710,6 +712,7 @@ func (f *BlockFetcher) loop() { if matched { task.transactions = append(task.transactions[:i], task.transactions[i+1:]...) task.uncles = append(task.uncles[:i], task.uncles[i+1:]...) + task.sidecars = append(task.sidecars[:i], task.sidecars[i+1:]...) i-- continue } diff --git a/eth/gasprice/gasprice_test.go b/eth/gasprice/gasprice_test.go index 79217502f..0475ca096 100644 --- a/eth/gasprice/gasprice_test.go +++ b/eth/gasprice/gasprice_test.go @@ -170,7 +170,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke } chain.InsertChain(blocks) chain.SetFinalized(chain.GetBlockByNumber(25).Header()) - chain.SetSafe(chain.GetBlockByNumber(25).Header()) + // chain.SetSafe(chain.GetBlockByNumber(25).Header()) return &testBackend{chain: chain, pending: pending} } diff --git a/eth/handler_eth.go b/eth/handler_eth.go index f1284c10e..457d48706 100644 --- a/eth/handler_eth.go +++ b/eth/handler_eth.go @@ -65,7 +65,7 @@ func (h *ethHandler) Handle(peer *eth.Peer, packet eth.Packet) error { return h.handleBlockAnnounces(peer, hashes, numbers) case *eth.NewBlockPacket: - return h.handleBlockBroadcast(peer, packet.Block, packet.TD) + return h.handleBlockBroadcast(peer, packet) case *eth.NewPooledTransactionHashesPacket: return h.txFetcher.Notify(peer.ID(), packet.Types, packet.Sizes, packet.Hashes) @@ -114,13 +114,20 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash, // handleBlockBroadcast is invoked from a peer's message handler when it transmits a // block broadcast for the local node to process. -func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block, td *big.Int) error { +func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, packet *eth.NewBlockPacket) error { // Drop all incoming block announces from the p2p network if // the chain already entered the pos stage and disconnect the // remote peer. if h.merger.PoSFinalized() { return errors.New("disallowed block broadcast") } + block := packet.Block + td := packet.TD + sidecars := packet.Sidecars + if sidecars != nil { + block = block.WithSidecars(sidecars) + } + // Schedule the block for import h.blockFetcher.Enqueue(peer.ID(), block) diff --git a/eth/protocols/eth/broadcast.go b/eth/protocols/eth/broadcast.go index b8224577d..9ded9db6a 100644 --- a/eth/protocols/eth/broadcast.go +++ b/eth/protocols/eth/broadcast.go @@ -46,7 +46,7 @@ func (p *Peer) broadcastBlocks() { if err := p.SendNewBlock(prop.block, prop.td); err != nil { return } - p.Log().Trace("Propagated block", "number", prop.block.Number(), "hash", prop.block.Hash(), "td", prop.td) + p.Log().Trace("Propagated block", "number", prop.block.Number(), "hash", prop.block.Hash(), "td", prop.td, "sidecars", len(prop.block.Sidecars())) case block := <-p.queuedBlockAnns: if err := p.SendNewBlockHashes([]common.Hash{block.Hash()}, []uint64{block.NumberU64()}); err != nil { diff --git a/eth/protocols/eth/handlers.go b/eth/protocols/eth/handlers.go index f0cdbc004..67247d9e1 100644 --- a/eth/protocols/eth/handlers.go +++ b/eth/protocols/eth/handlers.go @@ -224,10 +224,24 @@ func ServiceGetBlockBodiesQuery(chain *core.BlockChain, query GetBlockBodiesRequ lookups >= 2*maxBodiesServe { break } - if data := chain.GetBodyRLP(hash); len(data) != 0 { - bodies = append(bodies, data) - bytes += len(data) + body := chain.GetBody(hash) + if body == nil { + continue + } + sidecars := chain.GetSidecarsByHash(hash) + bodyWithSidecars := &BlockBody{ + Transactions: body.Transactions, + Uncles: body.Uncles, + Withdrawals: body.Withdrawals, + Sidecars: sidecars, + } + enc, err := rlp.EncodeToBytes(bodyWithSidecars) + if err != nil { + log.Error("block body encode err", "hash", hash, "err", err) + continue } + bodies = append(bodies, enc) + bytes += len(enc) } return bodies } @@ -293,6 +307,7 @@ func handleNewBlock(backend Backend, msg Decoder, peer *Peer) error { if err := msg.Decode(ann); err != nil { return fmt.Errorf("%w: message %v: %v", errDecode, msg, err) } + // Now that we have our packet, perform operations using the interface methods if err := ann.sanityCheck(); err != nil { return err } diff --git a/eth/protocols/eth/peer.go b/eth/protocols/eth/peer.go index b150e0504..6f394478e 100644 --- a/eth/protocols/eth/peer.go +++ b/eth/protocols/eth/peer.go @@ -292,8 +292,9 @@ func (p *Peer) SendNewBlock(block *types.Block, td *big.Int) error { // Mark all the block hash as known, but ensure we don't overflow our limits p.knownBlocks.Add(block.Hash()) return p2p.Send(p.rw, NewBlockMsg, &NewBlockPacket{ - Block: block, - TD: td, + Block: block, + TD: td, + Sidecars: block.Sidecars(), }) } diff --git a/eth/protocols/eth/protocol.go b/eth/protocols/eth/protocol.go index 2c819a463..7e4633726 100644 --- a/eth/protocols/eth/protocol.go +++ b/eth/protocols/eth/protocol.go @@ -186,8 +186,9 @@ type BlockHeadersRLPPacket struct { // NewBlockPacket is the network packet for the block propagation message. type NewBlockPacket struct { - Block *types.Block - TD *big.Int + Block *types.Block + TD *big.Int + Sidecars types.BlobSidecars `rlp:"optional"` } // sanityCheck verifies that the values are reasonable, as a DoS protection @@ -200,6 +201,15 @@ func (request *NewBlockPacket) sanityCheck() error { if tdlen := request.TD.BitLen(); tdlen > 100 { return fmt.Errorf("too large block TD: bitlen %d", tdlen) } + + if len(request.Sidecars) > 0 { + for _, sidecar := range request.Sidecars { + if err := sidecar.SanityCheck(request.Block.Number(), request.Block.Hash()); err != nil { + return err + } + } + } + return nil } @@ -238,21 +248,23 @@ type BlockBody struct { Transactions []*types.Transaction // Transactions contained within a block Uncles []*types.Header // Uncles contained within a block Withdrawals []*types.Withdrawal `rlp:"optional"` // Withdrawals contained within a block + Sidecars types.BlobSidecars `rlp:"optional"` // Sidecars contained within a block } // Unpack retrieves the transactions and uncles from the range packet and returns // them in a split flat format that's more consistent with the internal data structures. -func (p *BlockBodiesResponse) Unpack() ([][]*types.Transaction, [][]*types.Header, [][]*types.Withdrawal) { +func (p *BlockBodiesResponse) Unpack() ([][]*types.Transaction, [][]*types.Header, [][]*types.Withdrawal, []types.BlobSidecars) { // TODO(matt): add support for withdrawals to fetchers var ( txset = make([][]*types.Transaction, len(*p)) uncleset = make([][]*types.Header, len(*p)) withdrawalset = make([][]*types.Withdrawal, len(*p)) + sidecarset = make([]types.BlobSidecars, len(*p)) ) for i, body := range *p { - txset[i], uncleset[i], withdrawalset[i] = body.Transactions, body.Uncles, body.Withdrawals + txset[i], uncleset[i], withdrawalset[i], sidecarset[i] = body.Transactions, body.Uncles, body.Withdrawals, body.Sidecars } - return txset, uncleset, withdrawalset + return txset, uncleset, withdrawalset, sidecarset } // GetReceiptsRequest represents a block receipts query. diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index d5298b408..2d3a9932f 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -118,6 +118,26 @@ func (ec *Client) BlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumb return r, err } +// BlobSidecars return the Sidecars of a given block number or hash. +func (ec *Client) BlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) ([]*types.BlobSidecar, error) { + var r []*types.BlobSidecar + err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecars", blockNrOrHash.String()) + if err == nil && r == nil { + return nil, ethereum.NotFound + } + return r, err +} + +// BlobSidecarByTxHash return a sidecar of a given blob transaction +func (ec *Client) BlobSidecarByTxHash(ctx context.Context, hash common.Hash) (*types.BlobSidecar, error) { + var r *types.BlobSidecar + err := ec.c.CallContext(ctx, &r, "eth_getBlobSidecarByTxHash", hash) + if err == nil && r == nil { + return nil, ethereum.NotFound + } + return r, err +} + type rpcBlock struct { Hash common.Hash `json:"hash"` Transactions []rpcTransaction `json:"transactions"` diff --git a/ethdb/database.go b/ethdb/database.go index 4d4817daf..59b9a1ff8 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -17,7 +17,11 @@ // Package ethdb defines the interfaces for an Ethereum data store. package ethdb -import "io" +import ( + "io" + + "github.com/ethereum/go-ethereum/params" +) // KeyValueReader wraps the Has and Get method of a backing data store. type KeyValueReader interface { @@ -130,6 +134,23 @@ type AncientWriter interface { // The second argument is a function that takes a raw entry and returns it // in the newest format. MigrateTable(string, func([]byte) ([]byte, error)) error + + // TruncateTableTail will truncate certain table to new tail + TruncateTableTail(kind string, tail uint64) (uint64, error) + + // ResetTable will reset certain table with new start point + ResetTable(kind string, startAt uint64, onlyEmpty bool) error +} + +type FreezerEnv struct { + ChainCfg *params.ChainConfig + BlobExtraReserve uint64 +} + +// AncientFreezer defines the help functions for freezing ancient data +type AncientFreezer interface { + // SetupFreezerEnv provides params.ChainConfig for checking hark forks, like isCancun. + SetupFreezerEnv(env *FreezerEnv) error } // AncientWriteOp is given to the function argument of ModifyAncients. @@ -188,5 +209,6 @@ type Database interface { Stater Compacter Snapshotter + AncientFreezer io.Closer } diff --git a/ethdb/remotedb/remotedb.go b/ethdb/remotedb/remotedb.go index c1c803caf..ee16d861f 100644 --- a/ethdb/remotedb/remotedb.go +++ b/ethdb/remotedb/remotedb.go @@ -106,6 +106,16 @@ func (db *Database) TruncateTail(n uint64) (uint64, error) { panic("not supported") } +// TruncateTableTail will truncate certain table to new tail +func (db *Database) TruncateTableTail(kind string, tail uint64) (uint64, error) { + panic("not supported") +} + +// ResetTable will reset certain table with new start point +func (db *Database) ResetTable(kind string, startAt uint64, onlyEmpty bool) error { + panic("not supported") +} + func (db *Database) Sync() error { return nil } @@ -147,6 +157,10 @@ func (db *Database) Close() error { return nil } +func (db *Database) SetupFreezerEnv(env *ethdb.FreezerEnv) error { + panic("not supported") +} + func New(client *rpc.Client) ethdb.Database { return &Database{ remote: client, diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a4aada1ea..2c6d7f3e1 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -35,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -944,6 +945,56 @@ func (s *BlockChainAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc. return result, nil } +func (s *BlockChainAPI) GetBlobSidecars(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, fullBlob *bool) ([]map[string]interface{}, error) { + showBlob := true + if fullBlob != nil { + showBlob = *fullBlob + } + header, err := s.b.HeaderByNumberOrHash(ctx, blockNrOrHash) + if header == nil || err != nil { + // When the block doesn't exist, the RPC method should return JSON null + // as per specification. + return nil, nil + } + blobSidecars, err := s.b.GetBlobSidecars(ctx, header.Hash()) + if err != nil || blobSidecars == nil { + return nil, nil + } + result := make([]map[string]interface{}, len(blobSidecars)) + for i, sidecar := range blobSidecars { + result[i] = marshalBlobSidecar(sidecar, showBlob) + } + return result, nil +} + +func (s *BlockChainAPI) GetBlobSidecarByTxHash(ctx context.Context, hash common.Hash, fullBlob *bool) (map[string]interface{}, error) { + showBlob := true + if fullBlob != nil { + showBlob = *fullBlob + } + txTarget, blockHash, _, Index := rawdb.ReadTransaction(s.b.ChainDb(), hash) + if txTarget == nil { + return nil, nil + } + block, err := s.b.BlockByHash(ctx, blockHash) + if block == nil || err != nil { + // When the block doesn't exist, the RPC method should return JSON null + // as per specification. + return nil, nil + } + blobSidecars, err := s.b.GetBlobSidecars(ctx, blockHash) + if err != nil || blobSidecars == nil || len(blobSidecars) == 0 { + return nil, nil + } + for _, sidecar := range blobSidecars { + if sidecar.TxIndex == Index { + return marshalBlobSidecar(sidecar, showBlob), nil + } + } + + return nil, nil +} + // OverrideAccount indicates the overriding fields of account during the execution // of a message call. // Note, state and stateDiff can't be specified at the same time. If state is @@ -1724,6 +1775,35 @@ func marshalReceipt(receipt *types.Receipt, blockHash common.Hash, blockNumber u return fields } +func marshalBlobSidecar(sidecar *types.BlobSidecar, fullBlob bool) map[string]interface{} { + fields := map[string]interface{}{ + "blockHash": sidecar.BlockHash, + "blockNumber": hexutil.EncodeUint64(sidecar.BlockNumber.Uint64()), + "txHash": sidecar.TxHash, + "txIndex": hexutil.EncodeUint64(sidecar.TxIndex), + } + fields["blobSidecar"] = marshalBlob(sidecar.BlobTxSidecar, fullBlob) + return fields +} + +func marshalBlob(blobTxSidecar types.BlobTxSidecar, fullBlob bool) map[string]interface{} { + fields := map[string]interface{}{ + "blobs": blobTxSidecar.Blobs, + "commitments": blobTxSidecar.Commitments, + "proofs": blobTxSidecar.Proofs, + } + if !fullBlob { + var blobs []common.Hash + for _, blob := range blobTxSidecar.Blobs { + var value common.Hash + copy(value[:], blob[:32]) + blobs = append(blobs, value) + } + fields["blobs"] = blobs + } + return fields +} + // sign is a helper function that signs a transaction with the private key of the given address. func (s *TransactionAPI) sign(addr common.Address, tx *types.Transaction) (*types.Transaction, error) { // Look up the wallet containing the requested signer diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 4e6d21444..f61fd8285 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -556,6 +556,14 @@ func (b testBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.R receipts := rawdb.ReadReceipts(b.db, hash, header.Number.Uint64(), header.Time, b.chain.Config()) return receipts, nil } +func (b testBackend) GetBlobSidecars(ctx context.Context, hash common.Hash) (types.BlobSidecars, error) { + header, err := b.HeaderByHash(ctx, hash) + if header == nil || err != nil { + return nil, err + } + blobSidecars := rawdb.ReadBlobSidecars(b.db, hash, header.Number.Uint64()) + return blobSidecars, nil +} func (b testBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int { if b.pending != nil && hash == b.pending.Hash() { return nil diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 3b366439e..c54b88bc6 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -72,6 +72,7 @@ type Backend interface { SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription + GetBlobSidecars(ctx context.Context, hash common.Hash) (types.BlobSidecars, error) // Transaction pool API SendTx(ctx context.Context, signedTx *types.Transaction) error diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 6118b2631..3fea4a253 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -365,6 +365,9 @@ func (b *backendMock) GetReceipts(ctx context.Context, hash common.Hash) (types. func (b *backendMock) GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error) { return nil, nil } +func (b *backendMock) GetBlobSidecars(ctx context.Context, hash common.Hash) (types.BlobSidecars, error) { + return nil, nil +} func (b *backendMock) GetTd(ctx context.Context, hash common.Hash) *big.Int { return nil } func (b *backendMock) GetEVM(ctx context.Context, msg *core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM { return nil diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index b86b5909d..4055084e0 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -622,6 +622,16 @@ web3._extend({ call: 'eth_getBlockReceipts', params: 1, }), + new web3._extend.Method({ + name: 'getBlobSidecars', + call: 'eth_getBlobSidecars', + params: 2, + }), + new web3._extend.Method({ + name: 'getBlobSidecarByTxHash', + call: 'eth_getBlobSidecarByTxHash', + params: 2, + }), ], properties: [ new web3._extend.Property({ diff --git a/miner/payload_building.go b/miner/payload_building.go index 719736c47..1ac3cd1c5 100644 --- a/miner/payload_building.go +++ b/miner/payload_building.go @@ -71,7 +71,7 @@ type Payload struct { id engine.PayloadID empty *types.Block full *types.Block - sidecars []*types.BlobTxSidecar + sidecars types.BlobSidecars fullFees *big.Int stop chan struct{} lock sync.Mutex diff --git a/miner/worker.go b/miner/worker.go index b52d9b0ea..f51c28a3c 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -93,7 +93,7 @@ type environment struct { header *types.Header txs []*types.Transaction receipts []*types.Receipt - sidecars []*types.BlobTxSidecar + sidecars types.BlobSidecars blobs int } @@ -114,8 +114,11 @@ func (env *environment) copy() *environment { cpy.txs = make([]*types.Transaction, len(env.txs)) copy(cpy.txs, env.txs) - cpy.sidecars = make([]*types.BlobTxSidecar, len(env.sidecars)) - copy(cpy.sidecars, env.sidecars) + if env.sidecars != nil { + cpy.sidecars = make(types.BlobSidecars, len(env.sidecars)) + copy(cpy.sidecars, env.sidecars) + cpy.blobs = env.blobs + } return cpy } @@ -155,8 +158,8 @@ type newWorkReq struct { type newPayloadResult struct { err error block *types.Block - fees *big.Int // total block fees - sidecars []*types.BlobTxSidecar // collected blobs of blob transactions + fees *big.Int // total block fees + sidecars types.BlobSidecars // collected blobs of blob transactions } // getWorkReq represents a request for getting a new sealing work with provided parameters. @@ -774,7 +777,7 @@ func (w *worker) commitTransaction(env *environment, tx *types.Transaction) ([]* } func (w *worker) commitBlobTransaction(env *environment, tx *types.Transaction) ([]*types.Log, error) { - sc := tx.BlobTxSidecar() + sc := types.NewBlobSidecarFromTx(tx) if sc == nil { panic("blob transaction without blobs in miner") } @@ -996,6 +999,12 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { header.GasLimit = core.CalcGasLimit(parentGasLimit, w.config.GasCeil) } } + // Run the consensus preparation with the default or customized consensus engine. + // Note that the `header.Time` may be changed. + if err := w.engine.Prepare(w.chain, header); err != nil { + log.Error("Failed to prepare header for sealing", "err", err) + return nil, err + } // Apply EIP-4844, EIP-4788. if w.chainConfig.IsCancun(header.Number, header.Time) { var excessBlobGas uint64 @@ -1008,11 +1017,9 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { header.BlobGasUsed = new(uint64) header.ExcessBlobGas = &excessBlobGas header.ParentBeaconRoot = genParams.beaconRoot - } - // Run the consensus preparation with the default or customized consensus engine. - if err := w.engine.Prepare(w.chain, header); err != nil { - log.Error("Failed to prepare header for sealing", "err", err) - return nil, err + if w.chainConfig.Oasys != nil { + header.WithdrawalsHash = &types.EmptyWithdrawalsHash + } } // Could potentially happen if starting to mine in an odd state. // Note genParams.coinbase can be different with header.Coinbase @@ -1198,6 +1205,10 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti if interval != nil { interval() } + // If Cancun enabled, sidecars can't be nil then. + if w.chainConfig.IsCancun(env.header.Number, env.header.Time) && env.sidecars == nil { + env.sidecars = make(types.BlobSidecars, 0) + } // Create a local environment copy, avoid the data race with snapshot state. // https://github.com/ethereum/go-ethereum/issues/24299 env := env.copy() @@ -1206,6 +1217,9 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti if err != nil { return err } + + block = block.WithSidecars(env.sidecars) + // If we're post merge, just ignore if !w.isTTDReached(block.Header()) { select { diff --git a/params/config.go b/params/config.go index d7f79eb9f..fe2731a71 100644 --- a/params/config.go +++ b/params/config.go @@ -234,6 +234,7 @@ var ( BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), ShanghaiTime: newUint64(1721910600), // Thu Jul 25 2024 21:30:00 GMT+0900 + CancunTime: newUint64(9999999999), Oasys: &OasysConfig{ Period: 15, @@ -255,6 +256,7 @@ var ( BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), ShanghaiTime: newUint64(1718600000), // Mon Jun 17 2024 13:53:20 GMT+0900 + CancunTime: newUint64(9999999999), Oasys: &OasysConfig{ Period: 15, @@ -695,7 +697,13 @@ func (c *ChainConfig) IsShanghai(num *big.Int, time uint64) bool { // IsCancun returns whether num is either equal to the Cancun fork time or greater. func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { - return c.IsLondon(num) && isTimestampForked(c.CancunTime, time) + cancunTime := c.CancunTime + if c.ChainID.Cmp(OasysMainnetChainConfig.ChainID) == 0 { + cancunTime = OasysMainnetChainConfig.CancunTime + } else if c.ChainID.Cmp(OasysTestnetChainConfig.ChainID) == 0 { + cancunTime = OasysTestnetChainConfig.CancunTime + } + return c.IsLondon(num) && isTimestampForked(cancunTime, time) } // IsPrague returns whether num is either equal to the Prague fork time or greater. @@ -760,7 +768,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error { {name: "grayGlacierBlock", block: c.GrayGlacierBlock, optional: true}, {name: "mergeNetsplitBlock", block: c.MergeNetsplitBlock, optional: true}, {name: "shanghaiTime", timestamp: c.ShanghaiTime}, - {name: "cancunTime", timestamp: c.CancunTime, optional: true}, + {name: "cancunTime", timestamp: c.CancunTime}, {name: "pragueTime", timestamp: c.PragueTime, optional: true}, {name: "verkleTime", timestamp: c.VerkleTime, optional: true}, } { diff --git a/params/network_params.go b/params/network_params.go index 9311b5e2d..8e417d09a 100644 --- a/params/network_params.go +++ b/params/network_params.go @@ -53,15 +53,17 @@ const ( // CheckpointProcessConfirmations is the number before a checkpoint is generated CheckpointProcessConfirmations = 256 - // FullImmutabilityThreshold is the number of blocks after which a chain segment is - // considered immutable (i.e. soft finality). It is used by the downloader as a - // hard limit against deep ancestors, by the blockchain against deep reorgs, by - // the freezer as the cutoff threshold and by clique as the snapshot trust limit. - FullImmutabilityThreshold = 90000 - // LightImmutabilityThreshold is the number of blocks after which a header chain // segment is considered immutable for light client(i.e. soft finality). It is used by // the downloader as a hard limit against deep ancestors, by the blockchain against deep // reorgs, by the light pruner as the pruning validity guarantee. LightImmutabilityThreshold = 30000 ) + +var ( + // FullImmutabilityThreshold is the number of blocks after which a chain segment is + // considered immutable (i.e. soft finality). It is used by the downloader as a + // hard limit against deep ancestors, by the blockchain against deep reorgs, by + // the freezer as the cutoff threshold and by clique as the snapshot trust limit. + FullImmutabilityThreshold uint64 = 90000 +) diff --git a/params/protocol_params.go b/params/protocol_params.go index 7eb63e89a..b80461050 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -175,6 +175,11 @@ const ( MaxBlobGasPerBlock = 6 * BlobTxBlobGasPerBlob // Maximum consumable blob gas for data blobs per block ) +var ( + MinBlocksForBlobRequests uint64 = 524288 // it keeps blob data available for ~18.2 days in local, ref: https://github.com/bnb-chain/BEPs/blob/master/BEPs/BEP-336.md#51-parameters. + DefaultExtraReserveForBlobRequests uint64 = 1 * (24 * 3600) / 3 // it adds more time for expired blobs for some request cases, like expiry blob when remote peer is syncing, default 1 day. +) + // Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174} From 5580dd37d30e35f6ac77c5f22d49133fc28c38c3 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 23 Oct 2024 19:38:02 +0800 Subject: [PATCH 08/22] import bsc PR #2428 --- core/blockchain_insert.go | 7 +++++-- miner/worker.go | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index 9bf662b6b..3fbfa2f08 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -48,16 +48,19 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn // If we're at the last block of the batch or report period reached, log if index == len(chain)-1 || elapsed >= statsReportLimit { // Count the number of transactions in this segment - var txs int + var txs, blobs int for _, block := range chain[st.lastIndex : index+1] { txs += len(block.Transactions()) + for _, sidecar := range block.Sidecars() { + blobs += len(sidecar.Blobs) + } } end := chain[index] // Assemble the log context and send it to the logger context := []interface{}{ "number", end.Number(), "hash", end.Hash(), - "blocks", st.processed, "txs", txs, "mgas", float64(st.usedGas) / 1000000, + "blocks", st.processed, "txs", txs, "blobs", blobs, "mgas", float64(st.usedGas) / 1000000, "elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed), } if timestamp := time.Unix(int64(end.Time()), 0); time.Since(timestamp) > time.Minute { diff --git a/miner/worker.go b/miner/worker.go index f51c28a3c..dd324cd83 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1227,8 +1227,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti fees := totalFees(block, receipts) feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether)) log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()), - "txs", env.tcount, "gas", block.GasUsed(), "fees", feesInEther, - "elapsed", common.PrettyDuration(time.Since(start))) + "txs", env.tcount, "blobs", env.blobs, "gas", block.GasUsed(), "fees", feesInEther, "elapsed", common.PrettyDuration(time.Since(start))) case <-w.exitCh: log.Info("Worker has exited") From 139de3fdbe78c52f4f144762086f69efa60d0bf3 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 23 Oct 2024 19:43:24 +0800 Subject: [PATCH 09/22] import bsc PR #2525 --- eth/fetcher/block_fetcher.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eth/fetcher/block_fetcher.go b/eth/fetcher/block_fetcher.go index a07df7b3e..edaec5b55 100644 --- a/eth/fetcher/block_fetcher.go +++ b/eth/fetcher/block_fetcher.go @@ -867,14 +867,18 @@ func (f *BlockFetcher) importBlocks(peer string, block *types.Block) { // Run the import on a new thread log.Debug("Importing propagated block", "peer", peer, "number", block.Number(), "hash", hash) go func() { - defer func() { f.done <- hash }() - // If the parent's unknown, abort insertion parent := f.getBlock(block.ParentHash()) if parent == nil { log.Debug("Unknown parent of propagated block", "peer", peer, "number", block.Number(), "hash", hash, "parent", block.ParentHash()) return } + + if block.Header().EmptyWithdrawalsHash() { + block = block.WithWithdrawals(make([]*types.Withdrawal, 0)) + } + + defer func() { f.done <- hash }() // Quickly validate the header and propagate the block if it passes switch err := f.verifyHeader(block.Header()); err { case nil: From b5aa4e28d03c26d395d09550657828bde476875f Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 23 Oct 2024 19:51:53 +0800 Subject: [PATCH 10/22] import bsc PR #2350 --- core/genesis.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/genesis.go b/core/genesis.go index 615908db2..558ea2fff 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -431,6 +431,10 @@ func (g *Genesis) ToBlock() *types.Block { withdrawals = make([]*types.Withdrawal, 0) } if conf.IsCancun(num, g.Timestamp) { + if conf.Oasys != nil { + head.WithdrawalsHash = &types.EmptyWithdrawalsHash + } + // EIP-4788: The parentBeaconBlockRoot of the genesis block is always // the zero hash. This is because the genesis block does not have a parent // by definition. From 8e014090e25f37eb12931cac4369922bdf6bc041 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 23 Oct 2024 20:18:45 +0800 Subject: [PATCH 11/22] import bsc PR #2311 --- cmd/evm/internal/t8ntool/execution.go | 2 +- core/chain_makers_test.go | 6 +- core/state_processor.go | 11 ++- core/txpool/blobpool/blobpool.go | 6 +- eth/catalyst/api_test.go | 8 +-- eth/catalyst/simulated_beacon.go | 21 +++++- eth/tracers/native/prestate.go | 7 ++ ethclient/gethclient/gethclient.go | 6 ++ internal/jsre/deps/web3.js | 97 ++++++++++++++++----------- params/protocol_params.go | 4 +- 10 files changed, 111 insertions(+), 57 deletions(-) diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index cb975054c..0735a05d6 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -169,7 +169,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, // Calculate the BlobBaseFee var excessBlobGas uint64 if pre.Env.ExcessBlobGas != nil { - excessBlobGas := *pre.Env.ExcessBlobGas + excessBlobGas = *pre.Env.ExcessBlobGas vmContext.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas) } else { // If it is not explicitly defined, but we have the parent values, we try diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index b46b898af..a2ec9e650 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -47,8 +47,8 @@ func TestGeneratePOSChain(t *testing.T) { gspec = &Genesis{ Config: &config, Alloc: types.GenesisAlloc{ - address: {Balance: funds}, - params.BeaconRootsStorageAddress: {Balance: common.Big0, Code: asm4788}, + address: {Balance: funds}, + params.BeaconRootsAddress: {Balance: common.Big0, Code: asm4788}, }, BaseFee: big.NewInt(params.InitialBaseFee), Difficulty: common.Big1, @@ -180,7 +180,7 @@ func TestGeneratePOSChain(t *testing.T) { } state, _ := blockchain.State() idx := block.Time()%8191 + 8191 - got := state.GetState(params.BeaconRootsStorageAddress, common.BigToHash(new(big.Int).SetUint64(idx))) + got := state.GetState(params.BeaconRootsAddress, common.BigToHash(new(big.Int).SetUint64(idx))) if got != want { t.Fatalf("block %d, wrong parent beacon root in state: got %s, want %s", i, got, want) } diff --git a/core/state_processor.go b/core/state_processor.go index 8db1c2d1a..6dd3ffff1 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -204,6 +204,13 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo // ProcessBeaconBlockRoot applies the EIP-4788 system call to the beacon block root // contract. This method is exported to be used in tests. func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *state.StateDB) { + // Return immediately if beaconRoot equals the zero hash when using the Oasys engine. + if beaconRoot == (common.Hash{}) { + if chainConfig := vmenv.ChainConfig(); chainConfig != nil && chainConfig.Oasys != nil { + return + } + } + // If EIP-4788 is enabled, we need to invoke the beaconroot storage contract with // the new root msg := &Message{ @@ -212,11 +219,11 @@ func ProcessBeaconBlockRoot(beaconRoot common.Hash, vmenv *vm.EVM, statedb *stat GasPrice: common.Big0, GasFeeCap: common.Big0, GasTipCap: common.Big0, - To: ¶ms.BeaconRootsStorageAddress, + To: ¶ms.BeaconRootsAddress, Data: beaconRoot[:], } vmenv.Reset(NewEVMTxContext(msg), statedb) - statedb.AddAddressToAccessList(params.BeaconRootsStorageAddress) + statedb.AddAddressToAccessList(params.BeaconRootsAddress) _, _, _ = vmenv.Call(vm.AccountRef(msg.From), *msg.To, msg.Data, 30_000_000, common.U2560) statedb.Finalise(true) } diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index ac34dc4f1..705207dbb 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1135,8 +1135,12 @@ func (p *BlobPool) validateTx(tx *types.Transaction) error { next = p.state.GetNonce(from) ) if uint64(len(p.index[from])) > tx.Nonce()-next { - // Account can support the replacement, but the price bump must also be met prev := p.index[from][int(tx.Nonce()-next)] + // Ensure the transaction is different than the one tracked locally + if prev.hash == tx.Hash() { + return txpool.ErrAlreadyKnown + } + // Account can support the replacement, but the price bump must also be met switch { case tx.GasFeeCapIntCmp(prev.execFeeCap.ToBig()) <= 0: return fmt.Errorf("%w: new tx gas fee cap %v <= %v queued", txpool.ErrReplaceUnderpriced, tx.GasFeeCap(), prev.execFeeCap) diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 95681b9da..8c53956fe 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -72,8 +72,8 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) { genesis := &core.Genesis{ Config: &config, Alloc: types.GenesisAlloc{ - testAddr: {Balance: testBalance}, - params.BeaconRootsStorageAddress: {Balance: common.Big0, Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500")}, + testAddr: {Balance: testBalance}, + params.BeaconRootsAddress: {Balance: common.Big0, Code: common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604457602036146024575f5ffd5b620180005f350680545f35146037575f5ffd5b6201800001545f5260205ff35b6201800042064281555f359062018000015500")}, }, ExtraData: []byte("test genesis"), Timestamp: 9000, @@ -1655,10 +1655,10 @@ func TestParentBeaconBlockRoot(t *testing.T) { rootIdx = common.BigToHash(big.NewInt(int64((execData.ExecutionPayload.Timestamp % 98304) + 98304))) ) - if num := db.GetState(params.BeaconRootsStorageAddress, timeIdx); num != timeIdx { + if num := db.GetState(params.BeaconRootsAddress, timeIdx); num != timeIdx { t.Fatalf("incorrect number stored: want %s, got %s", timeIdx, num) } - if root := db.GetState(params.BeaconRootsStorageAddress, rootIdx); root != *blockParams.BeaconRoot { + if root := db.GetState(params.BeaconRootsAddress, rootIdx); root != *blockParams.BeaconRoot { t.Fatalf("incorrect root stored: want %s, got %s", *blockParams.BeaconRoot, root) } } diff --git a/eth/catalyst/simulated_beacon.go b/eth/catalyst/simulated_beacon.go index f1c5689e1..4ae60ed49 100644 --- a/eth/catalyst/simulated_beacon.go +++ b/eth/catalyst/simulated_beacon.go @@ -18,6 +18,7 @@ package catalyst import ( "crypto/rand" + "crypto/sha256" "errors" "math/big" "sync" @@ -27,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/txpool" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto/kzg4844" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" @@ -161,14 +163,14 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u SuggestedFeeRecipient: feeRecipient, Withdrawals: withdrawals, Random: random, - }, engine.PayloadV2, true) + BeaconRoot: &common.Hash{}, + }, engine.PayloadV3, true) if err != nil { return err } if fcResponse == engine.STATUS_SYNCING { return errors.New("chain rewind prevented invocation of payload creation") } - envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true) if err != nil { return err @@ -186,8 +188,21 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u } } + // Independently calculate the blob hashes from sidecars. + blobHashes := make([]common.Hash, 0) + if envelope.BlobsBundle != nil { + hasher := sha256.New() + for _, commit := range envelope.BlobsBundle.Commitments { + var c kzg4844.Commitment + if len(commit) != len(c) { + return errors.New("invalid commitment length") + } + copy(c[:], commit) + blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c)) + } + } // Mark the payload as canon - if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil { + if _, err = c.engineAPI.NewPayloadV3(*payload, blobHashes, &common.Hash{}); err != nil { return err } c.setCurrentState(payload.BlockHash, finalizedHash) diff --git a/eth/tracers/native/prestate.go b/eth/tracers/native/prestate.go index d7e10173c..c0977aeb6 100644 --- a/eth/tracers/native/prestate.go +++ b/eth/tracers/native/prestate.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" ) //go:generate go run github.com/fjl/gencodec -type account -field-override accountMarshaling -out gen_account_json.go @@ -109,6 +110,12 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo gasPrice := env.TxContext.GasPrice consumedGas := new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(t.gasLimit)) fromBal.Add(fromBal, new(big.Int).Add(value, consumedGas)) + + // Add blob fee to the sender's balance. + if env.Context.BlobBaseFee != nil && len(env.TxContext.BlobHashes) > 0 { + blobGas := uint64(params.BlobTxBlobGasPerBlob * len(env.TxContext.BlobHashes)) + fromBal.Add(fromBal, new(big.Int).Mul(env.Context.BlobBaseFee, new(big.Int).SetUint64(blobGas))) + } t.pre[from].Balance = fromBal t.pre[from].Nonce-- diff --git a/ethclient/gethclient/gethclient.go b/ethclient/gethclient/gethclient.go index 73d05d499..b1678b676 100644 --- a/ethclient/gethclient/gethclient.go +++ b/ethclient/gethclient/gethclient.go @@ -245,6 +245,12 @@ func toCallArg(msg ethereum.CallMsg) interface{} { if msg.AccessList != nil { arg["accessList"] = msg.AccessList } + if msg.BlobGasFeeCap != nil { + arg["maxFeePerBlobGas"] = (*hexutil.Big)(msg.BlobGasFeeCap) + } + if msg.BlobHashes != nil { + arg["blobVersionedHashes"] = msg.BlobHashes + } return arg } diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 0b360e741..d901e6cd7 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -1192,7 +1192,7 @@ module.exports = SolidityTypeInt; You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file param.js * @author Marek Kotewicz * @date 2015 @@ -1211,7 +1211,7 @@ var SolidityParam = function (value, offset) { /** * This method should be used to get length of params's dynamic part - * + * * @method dynamicPartLength * @returns {Number} length of dynamic part (in bytes) */ @@ -1239,7 +1239,7 @@ SolidityParam.prototype.withOffset = function (offset) { * @param {SolidityParam} result of combination */ SolidityParam.prototype.combine = function (param) { - return new SolidityParam(this.value + param.value); + return new SolidityParam(this.value + param.value); }; /** @@ -1271,8 +1271,8 @@ SolidityParam.prototype.offsetAsBytes = function () { */ SolidityParam.prototype.staticPart = function () { if (!this.isDynamic()) { - return this.value; - } + return this.value; + } return this.offsetAsBytes(); }; @@ -1304,7 +1304,7 @@ SolidityParam.prototype.encode = function () { * @returns {String} */ SolidityParam.encodeList = function (params) { - + // updating offsets var totalOffset = params.length * 32; var offsetParams = params.map(function (param) { @@ -1746,13 +1746,13 @@ if (typeof XMLHttpRequest === 'undefined') { /** * Utils - * + * * @module utils */ /** * Utility functions - * + * * @class [utils] config * @constructor */ @@ -1819,7 +1819,7 @@ module.exports = { You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file sha3.js * @author Marek Kotewicz * @date 2015 @@ -2739,7 +2739,7 @@ module.exports = AllSolidityEvents; You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file batch.js * @author Marek Kotewicz * @date 2015 @@ -2784,7 +2784,7 @@ Batch.prototype.execute = function () { requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); } }); - }); + }); }; module.exports = Batch; @@ -2971,7 +2971,7 @@ var ContractFactory = function (eth, abi) { */ this.new = function () { /*jshint maxcomplexity: 7 */ - + var contract = new Contract(this.eth, this.abi); // parse arguments @@ -3119,7 +3119,7 @@ module.exports = ContractFactory; You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file errors.js * @author Marek Kotewicz * @date 2015 @@ -3394,7 +3394,7 @@ var extend = function (web3) { } }; - ex.formatters = formatters; + ex.formatters = formatters; ex.utils = utils; ex.Method = Method; ex.Property = Property; @@ -3734,7 +3734,7 @@ var inputCallFormatter = function (options){ options.to = inputAddressFormatter(options.to); } - ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { + ['maxFeePerBlobGas', 'maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { return options[key] !== undefined; }).forEach(function(key){ options[key] = utils.fromDecimal(options[key]); @@ -3759,7 +3759,7 @@ var inputTransactionFormatter = function (options){ options.to = inputAddressFormatter(options.to); } - ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { + ['maxFeePerBlobGas', 'maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { return options[key] !== undefined; }).forEach(function(key){ options[key] = utils.fromDecimal(options[key]); @@ -3789,6 +3789,9 @@ var outputTransactionFormatter = function (tx){ if(tx.maxPriorityFeePerGas !== undefined) { tx.maxPriorityFeePerGas = utils.toBigNumber(tx.maxPriorityFeePerGas); } + if(tx.maxFeePerBlobGas !== undefined) { + tx.maxFeePerBlobGas = utils.toBigNumber(tx.maxFeePerBlobGas); + } tx.value = utils.toBigNumber(tx.value); return tx; }; @@ -3810,6 +3813,12 @@ var outputTransactionReceiptFormatter = function (receipt){ if(receipt.effectiveGasPrice !== undefined) { receipt.effectiveGasPrice = utils.toBigNumber(receipt.effectiveGasPrice); } + if(receipt.blobGasPrice !== undefined) { + receipt.blobGasPrice = utils.toBigNumber(receipt.blobGasPrice); + } + if(receipt.blobGasUsed !== undefined) { + receipt.blobGasUsed = utils.toBigNumber(receipt.blobGasUsed); + } if(utils.isArray(receipt.logs)) { receipt.logs = receipt.logs.map(function(log){ return outputLogFormatter(log); @@ -3831,6 +3840,12 @@ var outputBlockFormatter = function(block) { if (block.baseFeePerGas !== undefined) { block.baseFeePerGas = utils.toBigNumber(block.baseFeePerGas); } + if (block.blobGasUsed !== undefined) { + block.blobGasUsed = utils.toBigNumber(block.blobGasUsed); + } + if (block.excessBlobGas !== undefined) { + block.excessBlobGas = utils.toBigNumber(block.excessBlobGas); + } block.gasLimit = utils.toDecimal(block.gasLimit); block.gasUsed = utils.toDecimal(block.gasUsed); block.size = utils.toDecimal(block.size); @@ -4445,7 +4460,7 @@ module.exports = HttpProvider; You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file iban.js * @author Marek Kotewicz * @date 2015 @@ -4645,7 +4660,7 @@ Iban.prototype.address = function () { var base36 = this._iban.substr(4); var asBn = new BigNumber(base36, 36); return padLeft(asBn.toString(16), 20); - } + } return ''; }; @@ -4690,7 +4705,7 @@ var IpcProvider = function (path, net) { var _this = this; this.responseCallbacks = {}; this.path = path; - + this.connection = net.connect({path: this.path}); this.connection.on('error', function(e){ @@ -4700,7 +4715,7 @@ var IpcProvider = function (path, net) { this.connection.on('end', function(){ _this._timeout(); - }); + }); // LISTEN FOR CONNECTION RESPONSES @@ -4739,7 +4754,7 @@ Will parse the response and make an array out of it. IpcProvider.prototype._parseResponse = function(data) { var _this = this, returnValues = []; - + // DE-CHUNKER var dechunkedData = data .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ @@ -4843,7 +4858,7 @@ IpcProvider.prototype.send = function (payload) { try { result = JSON.parse(data); } catch(e) { - throw errors.InvalidResponse(data); + throw errors.InvalidResponse(data); } return result; @@ -5018,7 +5033,7 @@ Method.prototype.extractCallback = function (args) { /** * Should be called to check if the number of arguments is correct - * + * * @method validateArgs * @param {Array} arguments * @throws {Error} if it is not @@ -5031,7 +5046,7 @@ Method.prototype.validateArgs = function (args) { /** * Should be called to format input args of method - * + * * @method formatInput * @param {Array} * @return {Array} @@ -5085,7 +5100,7 @@ Method.prototype.attachToObject = function (obj) { obj[name[0]] = obj[name[0]] || {}; obj[name[0]][name[1]] = func; } else { - obj[name[0]] = func; + obj[name[0]] = func; } }; @@ -5148,8 +5163,8 @@ var DB = function (web3) { this._requestManager = web3._requestManager; var self = this; - - methods().forEach(function(method) { + + methods().forEach(function(method) { method.attachToObject(self); method.setRequestManager(web3._requestManager); }); @@ -5574,7 +5589,7 @@ var Net = function (web3) { var self = this; - properties().forEach(function(p) { + properties().forEach(function(p) { p.attachToObject(self); p.setRequestManager(web3._requestManager); }); @@ -6133,7 +6148,7 @@ module.exports = { You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file namereg.js * @author Marek Kotewicz * @date 2015 @@ -6320,7 +6335,7 @@ module.exports = Property; You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file requestmanager.js * @author Jeffrey Wilcke * @author Marek Kotewicz @@ -6387,7 +6402,7 @@ RequestManager.prototype.sendAsync = function (data, callback) { if (err) { return callback(err); } - + if (!Jsonrpc.isValidResponse(result)) { return callback(errors.InvalidResponse(result)); } @@ -6420,7 +6435,7 @@ RequestManager.prototype.sendBatch = function (data, callback) { } callback(err, results); - }); + }); }; /** @@ -6524,7 +6539,7 @@ RequestManager.prototype.poll = function () { } var payload = Jsonrpc.toBatchPayload(pollsData); - + // map the request id to they poll id var pollsIdMap = {}; payload.forEach(function(load, index){ @@ -6554,7 +6569,7 @@ RequestManager.prototype.poll = function () { } else return false; }).filter(function (result) { - return !!result; + return !!result; }).filter(function (result) { var valid = Jsonrpc.isValidResponse(result); if (!valid) { @@ -6629,16 +6644,16 @@ var pollSyncing = function(self) { self.callbacks.forEach(function (callback) { if (self.lastSyncState !== sync) { - + // call the callback with true first so the app can stop anything, before receiving the sync data if(!self.lastSyncState && utils.isObject(sync)) callback(null, true); - + // call on the next CPU cycle, so the actions of the sync stop can be processes first setTimeout(function() { callback(null, sync); }, 0); - + self.lastSyncState = sync; } }); @@ -6693,7 +6708,7 @@ module.exports = IsSyncing; You should have received a copy of the GNU Lesser General Public License along with web3.js. If not, see . */ -/** +/** * @file transfer.js * @author Marek Kotewicz * @date 2015 @@ -6712,7 +6727,7 @@ var exchangeAbi = require('../contracts/SmartExchange.json'); * @param {Function} callback, callback */ var transfer = function (eth, from, to, value, callback) { - var iban = new Iban(to); + var iban = new Iban(to); if (!iban.isValid()) { throw new Error('invalid iban address'); } @@ -6720,7 +6735,7 @@ var transfer = function (eth, from, to, value, callback) { if (iban.isDirect()) { return transferToAddress(eth, from, iban.address(), value, callback); } - + if (!callback) { var address = eth.icapNamereg().addr(iban.institution()); return deposit(eth, from, address, value, iban.client()); @@ -6729,7 +6744,7 @@ var transfer = function (eth, from, to, value, callback) { eth.icapNamereg().addr(iban.institution(), function (err, address) { return deposit(eth, from, address, value, iban.client(), callback); }); - + }; /** diff --git a/params/protocol_params.go b/params/protocol_params.go index b80461050..0262cdca7 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -189,8 +189,8 @@ var ( MinimumDifficulty = big.NewInt(131072) // The minimum that the difficulty may ever be. DurationLimit = big.NewInt(13) // The decision boundary on the blocktime duration used to determine whether difficulty should go up or not. - // BeaconRootsStorageAddress is the address where historical beacon roots are stored as per EIP-4788 - BeaconRootsStorageAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02") + // BeaconRootsAddress is the address where historical beacon roots are stored as per EIP-4788 + BeaconRootsAddress = common.HexToAddress("0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02") // SystemAddress is where the system-transaction is sent from as per EIP-4788 SystemAddress common.Address = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") ) From 884aee64ff609b8663cdd3810421c21f7cc058b7 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 23 Oct 2024 20:38:36 +0800 Subject: [PATCH 12/22] import bsc PR #2337 --- core/blockchain.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/blockchain.go b/core/blockchain.go index 908f62ec0..474709179 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -786,6 +786,7 @@ func (bc *BlockChain) setHeadBeyondRoot(head uint64, time uint64, root common.Ha // The header, total difficulty and canonical hash will be // removed in the hc.SetHead function. rawdb.DeleteBody(db, hash, num) + rawdb.DeleteBlobSidecars(db, hash, num) rawdb.DeleteReceipts(db, hash, num) } // Todo(rjl493456442) txlookup, bloombits, etc @@ -1216,7 +1217,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [ // Write all chain data to ancients. td := bc.GetTd(first.Hash(), first.NumberU64()) - writeSize, err := rawdb.WriteAncientBlocks(bc.db, blockChain, receiptChain, td) + writeSize, err := rawdb.WriteAncientBlocksWithBlobs(bc.db, blockChain, receiptChain, td) if err != nil { log.Error("Error importing chain data to ancients", "err", err) return 0, err From 4a3a7237bd3237fc55d27f2c13b0a5d20ffcefe9 Mon Sep 17 00:00:00 2001 From: ironbeer <7997273+ironbeer@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:27:45 +0900 Subject: [PATCH 13/22] Updated with `gencodec -dir eth/ethconfig/ -type Config -formats toml -out eth/ethconfig/gen_config.go` (#94) --- eth/ethconfig/gen_config.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index 2abddc9e0..aa67aaaae 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -56,6 +56,7 @@ func (c Config) MarshalTOML() (interface{}, error) { RPCTxFeeCap float64 OverrideCancun *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` + BlobExtraReserve uint64 } var enc Config enc.Genesis = c.Genesis @@ -97,6 +98,7 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.RPCTxFeeCap = c.RPCTxFeeCap enc.OverrideCancun = c.OverrideCancun enc.OverrideVerkle = c.OverrideVerkle + enc.BlobExtraReserve = c.BlobExtraReserve return &enc, nil } @@ -142,6 +144,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { RPCTxFeeCap *float64 OverrideCancun *uint64 `toml:",omitempty"` OverrideVerkle *uint64 `toml:",omitempty"` + BlobExtraReserve *uint64 } var dec Config if err := unmarshal(&dec); err != nil { @@ -264,5 +267,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.OverrideVerkle != nil { c.OverrideVerkle = dec.OverrideVerkle } + if dec.BlobExtraReserve != nil { + c.BlobExtraReserve = *dec.BlobExtraReserve + } return nil } From c4d4b3a81e824e901347ad5ecccd18cb493b7e2b Mon Sep 17 00:00:00 2001 From: ironbeer <7997273+ironbeer@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:28:08 +0900 Subject: [PATCH 14/22] Import eth/handler.go from bsc@v1.4.15 (#93) --- eth/handler.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/eth/handler.go b/eth/handler.go index d35caf2b0..174d598df 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -308,7 +308,18 @@ func newHandler(config *handlerConfig) (*handler, error) { } return h.chain.InsertChain(blocks) } - h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, + + broadcastBlockWithCheck := func(block *types.Block, propagate bool) { + if propagate { + if err := core.IsDataAvailable(h.chain, block); err != nil { + log.Error("Propagating block with invalid sidecars", "number", block.Number(), "hash", block.Hash(), "err", err) + return + } + } + h.BroadcastBlock(block, propagate) + } + + h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, broadcastBlockWithCheck, heighter, finalizeHeighter, nil, inserter, h.removePeer) fetchTx := func(peer string, hashes []common.Hash) error { From 9970144e5eac40535744c531d5bfa6e118bfb3cf Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 6 Nov 2024 11:42:36 +0800 Subject: [PATCH 15/22] Update core/blockchain.go Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com> --- core/blockchain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/blockchain.go b/core/blockchain.go index 474709179..c01f84e5a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1413,6 +1413,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. // if cancun is enabled, here need to write sidecars too if bc.chainConfig.IsCancun(block.Number(), block.Time()) { rawdb.WriteBlobSidecars(blockBatch, block.Hash(), block.NumberU64(), block.Sidecars()) + bc.sidecarsCache.Add(block.Hash(), block.Sidecars()) } if err := blockBatch.Write(); err != nil { log.Crit("Failed to write block into disk", "err", err) From 2d7867a1aeea8bbbb41cf84c7c554e2751121aef Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 6 Nov 2024 11:46:29 +0800 Subject: [PATCH 16/22] Update core/chain_makers.go Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com> --- core/chain_makers.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/chain_makers.go b/core/chain_makers.go index c69421792..529d01827 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -369,6 +369,9 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse if err != nil { panic(err) } + if block.Header().EmptyWithdrawalsHash() { + block = block.WithWithdrawals(make([]*types.Withdrawal, 0)) + } if config.IsCancun(block.Number(), block.Time()) { for _, s := range b.sidecars { s.BlockNumber = block.Number() From 4e4fa3ef3049154905c4cc87cee0a12855874510 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 6 Nov 2024 12:29:35 +0800 Subject: [PATCH 17/22] respond review by ironbeer part1 --- core/blockchain.go | 5 ++++- core/txpool/blobpool/blobpool.go | 6 +----- params/config.go | 10 +++++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 474709179..de0775383 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2071,7 +2071,10 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i for i := len(hashes) - 1; i >= 0; i-- { // Append the next block to our batch block := bc.GetBlock(hashes[i], numbers[i]) - if block != nil && bc.chainConfig.IsCancun(block.Number(), block.Time()) { + if block == nil { + log.Crit("Importing heavy sidechain block is nil", "hash", hashes[i], "number", numbers[i]) + } + if bc.chainConfig.IsCancun(block.Number(), block.Time()) { block = block.WithSidecars(bc.GetSidecarsByHash(hashes[i])) } diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index 705207dbb..ac34dc4f1 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1135,12 +1135,8 @@ func (p *BlobPool) validateTx(tx *types.Transaction) error { next = p.state.GetNonce(from) ) if uint64(len(p.index[from])) > tx.Nonce()-next { - prev := p.index[from][int(tx.Nonce()-next)] - // Ensure the transaction is different than the one tracked locally - if prev.hash == tx.Hash() { - return txpool.ErrAlreadyKnown - } // Account can support the replacement, but the price bump must also be met + prev := p.index[from][int(tx.Nonce()-next)] switch { case tx.GasFeeCapIntCmp(prev.execFeeCap.ToBig()) <= 0: return fmt.Errorf("%w: new tx gas fee cap %v <= %v queued", txpool.ErrReplaceUnderpriced, tx.GasFeeCap(), prev.execFeeCap) diff --git a/params/config.go b/params/config.go index a81cbd612..3ef4d9e8b 100644 --- a/params/config.go +++ b/params/config.go @@ -1049,7 +1049,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules chainID = new(big.Int) } // disallow setting Merge out of order - isMerge = isMerge && c.IsLondon(num) + isMerge = c.IsLondon(num) return Rules{ ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), @@ -1063,9 +1063,9 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules IsBerlin: c.IsBerlin(num), IsLondon: c.IsLondon(num), IsMerge: isMerge, - IsShanghai: isMerge && c.IsShanghai(num, timestamp), - IsCancun: isMerge && c.IsCancun(num, timestamp), - IsPrague: isMerge && c.IsPrague(num, timestamp), - IsVerkle: isMerge && c.IsVerkle(num, timestamp), + IsShanghai: c.IsShanghai(num, timestamp), + IsCancun: c.IsCancun(num, timestamp), + IsPrague: c.IsPrague(num, timestamp), + IsVerkle: c.IsVerkle(num, timestamp), } } From 543900648883f941d04eb24e01571c4acde1de41 Mon Sep 17 00:00:00 2001 From: ironbeer <7997273+ironbeer@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:01:38 +0900 Subject: [PATCH 18/22] Restore changes from 4e4fa3e (#95) --- core/txpool/blobpool/blobpool.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/txpool/blobpool/blobpool.go b/core/txpool/blobpool/blobpool.go index ac34dc4f1..705207dbb 100644 --- a/core/txpool/blobpool/blobpool.go +++ b/core/txpool/blobpool/blobpool.go @@ -1135,8 +1135,12 @@ func (p *BlobPool) validateTx(tx *types.Transaction) error { next = p.state.GetNonce(from) ) if uint64(len(p.index[from])) > tx.Nonce()-next { - // Account can support the replacement, but the price bump must also be met prev := p.index[from][int(tx.Nonce()-next)] + // Ensure the transaction is different than the one tracked locally + if prev.hash == tx.Hash() { + return txpool.ErrAlreadyKnown + } + // Account can support the replacement, but the price bump must also be met switch { case tx.GasFeeCapIntCmp(prev.execFeeCap.ToBig()) <= 0: return fmt.Errorf("%w: new tx gas fee cap %v <= %v queued", txpool.ErrReplaceUnderpriced, tx.GasFeeCap(), prev.execFeeCap) From f2557582ec26497ad58bee62bf56d08044d08732 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 6 Nov 2024 14:04:15 +0800 Subject: [PATCH 19/22] Update params/config.go Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com> --- params/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/params/config.go b/params/config.go index 3ef4d9e8b..36eb459e7 100644 --- a/params/config.go +++ b/params/config.go @@ -1049,7 +1049,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules chainID = new(big.Int) } // disallow setting Merge out of order - isMerge = c.IsLondon(num) + isMerge = isMerge && c.IsLondon(num) return Rules{ ChainID: new(big.Int).Set(chainID), IsHomestead: c.IsHomestead(num), From 123782f2103963beca2cd00f15fbdf632839a87c Mon Sep 17 00:00:00 2001 From: ironbeer <7997273+ironbeer@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:41:53 +0900 Subject: [PATCH 20/22] Import miner/worker.go from bsc@v1.4.15 (2) (#99) --- miner/worker.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index dd324cd83..2c2f5c8d4 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1205,6 +1205,16 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti if interval != nil { interval() } + // Withdrawals are set to nil here, because this is only called in PoW. + block, receipts, err := w.engine.FinalizeAndAssemble(w.chain, types.CopyHeader(env.header), env.state, env.txs, nil, env.receipts, nil) + if err != nil { + return err + } + + if block.Header().EmptyWithdrawalsHash() { + block = block.WithWithdrawals(make([]*types.Withdrawal, 0)) + } + // If Cancun enabled, sidecars can't be nil then. if w.chainConfig.IsCancun(env.header.Number, env.header.Time) && env.sidecars == nil { env.sidecars = make(types.BlobSidecars, 0) @@ -1212,11 +1222,6 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti // Create a local environment copy, avoid the data race with snapshot state. // https://github.com/ethereum/go-ethereum/issues/24299 env := env.copy() - // Withdrawals are set to nil here, because this is only called in PoW. - block, receipts, err := w.engine.FinalizeAndAssemble(w.chain, types.CopyHeader(env.header), env.state, env.txs, nil, env.receipts, nil) - if err != nil { - return err - } block = block.WithSidecars(env.sidecars) From 0a5f3befb0392901caaec5d879a72e23eba66ee2 Mon Sep 17 00:00:00 2001 From: ironbeer <7997273+ironbeer@users.noreply.github.com> Date: Mon, 11 Nov 2024 21:46:06 +0900 Subject: [PATCH 21/22] Import miner/worker.go from bsc@v1.4.15 (3) (#100) --- miner/worker.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index 2c2f5c8d4..19e86ebf2 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1016,10 +1016,14 @@ func (w *worker) prepareWork(genParams *generateParams) (*environment, error) { } header.BlobGasUsed = new(uint64) header.ExcessBlobGas = &excessBlobGas - header.ParentBeaconRoot = genParams.beaconRoot if w.chainConfig.Oasys != nil { header.WithdrawalsHash = &types.EmptyWithdrawalsHash } + if w.chainConfig.Oasys == nil { + header.ParentBeaconRoot = genParams.beaconRoot + } else { + header.ParentBeaconRoot = new(common.Hash) + } } // Could potentially happen if starting to mine in an odd state. // Note genParams.coinbase can be different with header.Coinbase From 63febf218ffc114cf9bbf8dbaaf6d2380aa874a0 Mon Sep 17 00:00:00 2001 From: tak Date: Wed, 13 Nov 2024 21:28:46 +0700 Subject: [PATCH 22/22] Update consensus/oasys/oasys.go Co-authored-by: ironbeer <7997273+ironbeer@users.noreply.github.com> --- consensus/oasys/oasys.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/oasys/oasys.go b/consensus/oasys/oasys.go index 5392a0721..6f7b69b5f 100644 --- a/consensus/oasys/oasys.go +++ b/consensus/oasys/oasys.go @@ -347,7 +347,7 @@ func (c *Oasys) verifyHeader(chain consensus.ChainHeaderReader, header *types.He case !header.EmptyWithdrawalsHash(): return errors.New("header has wrong WithdrawalsHash") } - if header.ParentBeaconRoot == nil { + if header.ParentBeaconRoot == nil || *header.ParentBeaconRoot != (common.Hash{}) { return errors.New("header is missing beaconRoot") } if err := eip4844.VerifyEIP4844Header(parent, header); err != nil {