Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

WIP - Protodanksharding #1930

Closed
wants to merge 194 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
194 commits
Select commit Hold shift + click to select a range
2a161dc
stashing
badgersrus May 22, 2024
1297fc0
regenerate mgmt contracts
badgersrus May 22, 2024
b33082c
stashing
badgersrus May 22, 2024
de4f443
fix blob serialization
badgersrus May 22, 2024
e56c531
stashing decoding
badgersrus May 22, 2024
25ebebf
merging
badgersrus May 23, 2024
ff5ec9f
fix merge
badgersrus May 23, 2024
b40af46
add switch to retry logic
badgersrus May 31, 2024
0f8a812
stashing for the weekend - rlp issue
badgersrus May 31, 2024
33c5c55
merge
badgersrus May 31, 2024
ee39410
stashing
badgersrus Jun 4, 2024
2e1397b
checkpoint before embarking on the geth upgrade & beacon chain
badgersrus Jun 4, 2024
ae1d639
remove unwanted files
badgersrus Jun 4, 2024
8b7b07e
checkpoint
badgersrus Jun 5, 2024
6ed3b57
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
badgersrus Jun 5, 2024
e9ef5c0
mining config working
badgersrus Jun 5, 2024
58487d3
stashing prysm 5.0.0 attempt
badgersrus Jun 12, 2024
8c2e861
remove docker pos
badgersrus Jun 12, 2024
9ac304e
stashing withdrawal hash error
badgersrus Jun 13, 2024
5df0b66
remove decodessz file
badgersrus Jun 13, 2024
cc3fdf7
add cancun signer
badgersrus Jun 13, 2024
44e9f35
fixed withdrawal hash issue
badgersrus Jun 14, 2024
93744b1
stashing
badgersrus Jun 24, 2024
f11978a
delete old geth gen config
badgersrus Jun 24, 2024
597f2c1
blah
badgersrus Jun 24, 2024
bddaa80
update start beacon params - NEW ERROR UNLOCKED
badgersrus Jun 25, 2024
9eef43a
stashing
badgersrus Jun 27, 2024
b4a218b
merging latest
badgersrus Jun 27, 2024
815e8fa
stashing
badgersrus Jul 1, 2024
635ae66
new error unlocked
badgersrus Jul 2, 2024
04ff2d9
stashing before I lose my mind
badgersrus Jul 2, 2024
2be235e
set execution endpoint with geth.ipc
badgersrus Jul 3, 2024
fc3298e
tidy up
badgersrus Jul 3, 2024
794164f
stashing
badgersrus Jul 3, 2024
c489974
stashing
badgersrus Jul 4, 2024
9ee0b71
stashing
badgersrus Jul 4, 2024
cd10cd3
trying a script version instead
badgersrus Jul 5, 2024
e0f65fd
stashing
badgersrus Jul 8, 2024
b1a27bb
dumping
badgersrus Jul 8, 2024
8ecdfc6
delete build contents
badgersrus Jul 8, 2024
c838582
script complete ... still [Cdoesn't work though
badgersrus Jul 9, 2024
ce367a2
stashing init-geth script & start-network script. geth Forkchoice req…
badgersrus Jul 9, 2024
782e39d
script working but timeout needs to be 10 minutes
badgersrus Jul 10, 2024
1a49fd6
stashing before I start messing around with ports
badgersrus Jul 10, 2024
9da3d92
tx minted test passing
badgersrus Jul 10, 2024
41da44a
Merge branch 'main' into will/upgrade-geth
badgersrus Jul 10, 2024
7d42308
update tests
badgersrus Jul 11, 2024
5c1b644
Merge branch 'will/upgrade-geth' of https://github.com/ten-protocol/g…
badgersrus Jul 11, 2024
471a715
missed files on commit
badgersrus Jul 11, 2024
944e0cb
lint
badgersrus Jul 11, 2024
f4f27b7
lint
badgersrus Jul 11, 2024
05742da
compile fix
badgersrus Jul 11, 2024
e0c2aca
lint;
badgersrus Jul 11, 2024
9dbeb5c
stashing at working pos network test
badgersrus Jul 11, 2024
b0c4d7f
fix script
badgersrus Jul 11, 2024
5c3b859
remove intermediate file
badgersrus Jul 11, 2024
bfa061a
add chainID to cli
badgersrus Jul 12, 2024
faf370d
add wait
badgersrus Jul 12, 2024
33de61d
add sleep to code for gh actions
badgersrus Jul 12, 2024
10ae46e
add new timeout
badgersrus Jul 12, 2024
aa057b3
set block number
badgersrus Jul 12, 2024
51cb790
update pr build
badgersrus Jul 12, 2024
f3c1abb
close UDP ports
badgersrus Jul 12, 2024
5075359
close UDP ports
badgersrus Jul 12, 2024
958b05a
add new sleep
badgersrus Jul 15, 2024
d15854d
move gethdata out of timestamped build path due to character limit
badgersrus Jul 15, 2024
1327e7d
remove crud
badgersrus Jul 15, 2024
f5a07dc
shorten build path
badgersrus Jul 15, 2024
146413a
see if this works
badgersrus Jul 15, 2024
f9b7cc6
lint
badgersrus Jul 15, 2024
cd4acf9
remove geth.ipc before uploading
badgersrus Jul 15, 2024
98934e5
clean up gethdata dir
badgersrus Jul 15, 2024
c7d2249
remove cleanup
badgersrus Jul 15, 2024
fea9d9c
upload only log files
badgersrus Jul 16, 2024
7220dc6
filter out .ipc from upload
badgersrus Jul 16, 2024
5fbb101
fix filtering
badgersrus Jul 16, 2024
01fcd09
homogenise chainID
badgersrus Jul 16, 2024
9da31cd
fix build path counter thing
badgersrus Jul 16, 2024
f475dfa
add sleep after kill process
badgersrus Jul 16, 2024
4e46a1f
make sure proccesses are killed before starting next one
badgersrus Jul 16, 2024
e426224
kill processes from script by process name instead of PID
badgersrus Jul 16, 2024
5cca098
fix kill script
badgersrus Jul 16, 2024
b57775c
ugh
badgersrus Jul 16, 2024
0d777be
define process and kill it
badgersrus Jul 16, 2024
1a44026
its a mess, lets see how it plays out cotton
badgersrus Jul 16, 2024
6494083
add chain ID to prysm config
badgersrus Jul 16, 2024
f575882
signing out
badgersrus Jul 16, 2024
735bef9
stashing
badgersrus Jul 19, 2024
b094c93
capture PIDS and kill processes - need to add network start ports
badgersrus Jul 19, 2024
d7aa1cd
add port offsets for tcp & udp
badgersrus Jul 22, 2024
c9e06e9
remove bind address crap
badgersrus Jul 22, 2024
dbd59f9
add auth port
badgersrus Jul 22, 2024
2c6011d
lint:
badgersrus Jul 22, 2024
6fda7fb
fix gateway test
badgersrus Jul 23, 2024
1b9ea1b
increase wait delay on bridge xfers
badgersrus Jul 23, 2024
3c32db5
increase timeouts
badgersrus Jul 23, 2024
da3f603
increase timeouts
badgersrus Jul 23, 2024
8fa9456
add longer timeout
badgersrus Jul 23, 2024
05a865c
increase sim timeout and add logging
badgersrus Jul 23, 2024
675dda7
increase enclave client timeout ... que?
badgersrus Jul 23, 2024
aa3cfd0
increase build PR timeout
badgersrus Jul 23, 2024
a08212b
remove unnessecary timeouts, bump pr timeout for full network test
badgersrus Jul 23, 2024
66da4cf
10min timeout
badgersrus Jul 23, 2024
01159fd
improve port killing on close
badgersrus Jul 24, 2024
0a8c7b8
stashing before changing build number
badgersrus Jul 24, 2024
b23aed2
clean up
badgersrus Jul 24, 2024
2a76c77
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
badgersrus Jul 24, 2024
ecc54df
bail on enclave config refactor
badgersrus Jul 24, 2024
19058c0
increase build limit and add overwrite logic
badgersrus Jul 24, 2024
f105827
remove unwanted file
badgersrus Jul 24, 2024
6eb6ffa
resolve conflicts
badgersrus Jul 24, 2024
7238659
Merge branch 'will/upgrade-geth' into will/proto-danksharding
badgersrus Jul 24, 2024
cc6c61f
stashing to run tests
badgersrus Jul 24, 2024
9d6c1a4
stashing
badgersrus Jul 25, 2024
e5c4822
docker host config
badgersrus Jul 25, 2024
4f7e98b
change ports back
badgersrus Jul 25, 2024
ff5bb08
add virtual hosts and cors to geth
badgersrus Jul 25, 2024
efb08bb
lint
badgersrus Jul 25, 2024
5d5d9f0
fix geth port
badgersrus Jul 26, 2024
9c06990
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
badgersrus Jul 29, 2024
ddf13a0
fix tengateway test
badgersrus Jul 29, 2024
ff52e8f
add legeacy peer deps to hh build
badgersrus Jul 30, 2024
f016a3a
try adding --force
badgersrus Jul 30, 2024
e9bb537
remove old name
badgersrus Jul 30, 2024
ac30842
remove force install on hhdeployer
badgersrus Jul 30, 2024
402ef86
merge in stefans fix
badgersrus Jul 31, 2024
3ddd6bd
fix conflicts
badgersrus Jul 31, 2024
50a6f61
Merge branch 'will/upgrade-geth' into will/proto-danksharding
badgersrus Jul 31, 2024
e1e127b
bump retry to 100% as enforced by geth
badgersrus Aug 2, 2024
bae1441
stashing beacon client API
badgersrus Aug 5, 2024
7834096
unit test for beacon client
badgersrus Aug 6, 2024
7c62bad
stashing before big refactor
badgersrus Aug 6, 2024
b009ea1
stashing fixed genesis api call
badgersrus Aug 6, 2024
05d84f5
merge latest
badgersrus Aug 7, 2024
5b45ed0
fixed beacon API calls
badgersrus Aug 7, 2024
b132793
stashing before merge
badgersrus Aug 8, 2024
4cd742f
stashing before merge
badgersrus Aug 8, 2024
1b82030
new encoding/ decoding method
badgersrus Aug 8, 2024
35fa041
rollup decoding fixed
badgersrus Aug 9, 2024
db23304
stashing
badgersrus Aug 9, 2024
b3de727
logging for comparison
badgersrus Aug 9, 2024
86f4c83
del
badgersrus Aug 9, 2024
db5eaa4
use new L1RollupHashes
badgersrus Aug 12, 2024
b91c82a
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
badgersrus Aug 14, 2024
10b4673
logging
badgersrus Aug 14, 2024
236afda
todo - fix duplicate rollups in validate chain map
badgersrus Aug 14, 2024
f3bad53
stashing
badgersrus Aug 19, 2024
7e53432
stashing logging
badgersrus Aug 20, 2024
36e4815
remove crud
badgersrus Aug 20, 2024
ae801e1
stashing failed rewrite
badgersrus Aug 20, 2024
484278a
Merge branch 'main' of https://github.com/ten-protocol/go-ten into HEAD
badgersrus Aug 22, 2024
402d3be
merging latest from main - nodes not healthy|
badgersrus Aug 23, 2024
12b2760
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
badgersrus Aug 23, 2024
07003dc
update hardcoding - enclave attestation error
badgersrus Aug 23, 2024
768cdb5
resolce merge
badgersrus Aug 23, 2024
9d4aa8c
clean up
badgersrus Aug 23, 2024
2f36005
clean up
badgersrus Aug 23, 2024
405b353
stashing'
badgersrus Aug 28, 2024
8da1bbc
full network test passing
badgersrus Aug 29, 2024
2678a51
fix sim test ports for beacon gateway
badgersrus Aug 29, 2024
bac9cd1
fixed sim test, smart contracts timing out
badgersrus Aug 30, 2024
cd9b782
Merge branch 'main' into will/proto-danksharding
badgersrus Aug 30, 2024
89e35d1
stashing
badgersrus Sep 2, 2024
d108243
stashing
badgersrus Sep 2, 2024
41006a2
remove tenscan timer
badgersrus Sep 2, 2024
a1c6587
stashing new grpc
badgersrus Sep 4, 2024
c95f40b
remove crap
badgersrus Sep 5, 2024
5af48c4
Merge branch 'main' into will/proto-danksharding
badgersrus Sep 5, 2024
a39536d
fix conflicts
badgersrus Sep 5, 2024
24aaad9
latest
badgersrus Sep 5, 2024
49e47b1
missing files
badgersrus Sep 5, 2024
9956d82
lint
badgersrus Sep 6, 2024
ed52222
fix crud
badgersrus Sep 6, 2024
6e297a7
resolve conflicts from main?
badgersrus Sep 6, 2024
de66fd1
lint
badgersrus Sep 6, 2024
016ea28
remove unused isLatest flag
badgersrus Sep 6, 2024
8fd4ed4
lint
badgersrus Sep 6, 2024
f002230
stashing for branch switch
badgersrus Sep 9, 2024
20de7b6
stashing
badgersrus Sep 10, 2024
6860e43
merge latest
badgersrus Sep 12, 2024
aafa982
fix test
badgersrus Sep 12, 2024
79df20a
regenerate abi
badgersrus Sep 12, 2024
f43704e
try new mock pos network
badgersrus Sep 13, 2024
f805358
Merge branch 'main' of https://github.com/ten-protocol/go-ten into wi…
badgersrus Sep 16, 2024
abd77aa
stashing to test main
badgersrus Sep 16, 2024
674c7e8
stashing
badgersrus Sep 16, 2024
742c0a2
stashing
badgersrus Sep 17, 2024
c049363
stashing before rewrite
badgersrus Sep 18, 2024
418ec9c
fix mock server
badgersrus Sep 18, 2024
2a226a8
stashing before branch switch
badgersrus Sep 19, 2024
32b7fd3
stashing
badgersrus Sep 19, 2024
990e0f4
stashing before rewrite
badgersrus Sep 19, 2024
d069a8c
rejecting blocks failure
badgersrus Sep 19, 2024
211757a
stashing
badgersrus Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
stashing to test main
  • Loading branch information
badgersrus committed Sep 16, 2024
commit abd77aa1a837124e9502227738dc027936eea21b
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
)

require (
Expand Down Expand Up @@ -81,12 +82,16 @@ require (
github.com/crate-crypto/go-kzg-4844 v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/deepmap/oapi-codegen v1.6.0 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dop251/goja v0.0.0-20230605162241-28ee0ee714f3 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ethereum/c-kzg-4844 v1.0.0 // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/ferranbt/fastssz v0.1.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
Expand All @@ -99,17 +104,23 @@ require (
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.19.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/graph-gophers/graphql-go v1.3.0 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/influxdata/influxdb-client-go/v2 v2.4.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 // indirect
Expand All @@ -120,6 +131,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/pointerstructure v1.2.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
Expand All @@ -131,7 +143,9 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
Expand Down Expand Up @@ -160,8 +174,10 @@ require (
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand Down
104 changes: 104 additions & 0 deletions go.sum

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions go/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ func (br *BlockAndReceipts) Receipts() L1Receipts {
// RelevantTransactions - returns slice containing only the transactions that have receipts with successful status.
func (br *BlockAndReceipts) RelevantTransactions() *types.Transactions {
if br.successfulTransactions != nil {
println("Successful txs")

stx := br.successfulTransactions
for _, tx := range *stx {
if tx.Type() == 0x03 {
Expand Down
2 changes: 2 additions & 0 deletions go/ethadapter/beacon_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (bc *BeaconHTTPClient) request(ctx context.Context, dest any, reqPath strin
base = "http://" + base
}
baseURL, err := url.Parse(base)

if err != nil {
return fmt.Errorf("failed to parse base URL: %w", err)
}
Expand Down Expand Up @@ -247,6 +248,7 @@ func (cl *L1BeaconClient) GetBlobSidecars(ctx context.Context, b *types.Header,
return nil, fmt.Errorf("error in converting ref.Time to slot: %w", err)
}

println("Fetching sidecar at slot: ", slot)
resp, err := cl.fetchSidecars(ctx, slot)
if err != nil {
return nil, fmt.Errorf("failed to fetch blob sidecars for slot %v block %v: %w", slot, b, err)
Expand Down
7 changes: 7 additions & 0 deletions go/ethadapter/blob_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,10 @@ func KZGToVersionedHash(commitment kzg4844.Commitment) (out common.Hash) {
func VerifyBlobProof(blob *kzg4844.Blob, commitment kzg4844.Commitment, proof kzg4844.Proof) error {
return kzg4844.VerifyBlobProof(blob, commitment, proof)
}

func TimeToSlot(timestamp uint64, genesisTime uint64, secondsPerSlot uint64) (uint64, error) {
if timestamp < genesisTime {
return 0, fmt.Errorf("provided timestamp (%v) precedes genesis time (%v)", timestamp, genesisTime)
}
return (timestamp - genesisTime) / secondsPerSlot, nil
}
1 change: 0 additions & 1 deletion go/host/enclave/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ func (g *Guardian) submitL1Block(block *common.L1Block, isLatest bool) (bool, er
// nullify all non-relevant transactions
txs := block.Transactions()
for i, rec := range receipts {
println("RECEIPTS ", i, " : ", rec)
// the FetchObscuroReceipts method returns dummy receipts on non-relevant positions.
if rec.BlockNumber != nil {
txWithReceipts = append(txWithReceipts, &common.TxAndReceipt{
Expand Down
1 change: 0 additions & 1 deletion go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ func (p *Publisher) ExtractTenTransactionsAndBlobs(block *types.Block) ([]*ethad
var blobs []*kzg4844.Blob
var err error
for _, tx := range block.Transactions() {
println("extracting txs from block with type: ", tx.Type())
t := p.mgmtContractLib.DecodeTx(tx)
if t == nil {
continue
Expand Down
127 changes: 56 additions & 71 deletions integration/ethereummock/beacon_client_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,26 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/log"
"github.com/ten-protocol/go-ten/go/ethadapter"
"io/fs"
"net"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"sync"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/beacon/engine"
"github.com/ethereum/go-ethereum/log"
)

const kzgBlobSize = 131072

// BeaconMock presents a beacon-node in testing, without leading any chain-building.
// This merely serves a fake beacon API, and holds on to blocks,
// to complement the actual block-building to happen in testing (e.g. through the fake consensus geth module).
type BeaconMock struct {
log log.Logger

// directory to store blob contents in after the blobs are persisted in a block
blobsDir string
blobs map[uint64][]*kzg4844.Blob
blobsLock sync.Mutex

beaconSrv *http.Server
Expand All @@ -39,13 +35,13 @@ type BeaconMock struct {
port int
}

func NewBeaconMock(log log.Logger, blobsDir string, genesisTime uint64, blockTime uint64, port int) *BeaconMock {
func NewBeaconMock(log log.Logger, genesisTime uint64, blockTime uint64, port int) *BeaconMock {
return &BeaconMock{
log: log,
blobsDir: blobsDir,
genesisTime: genesisTime,
blockTime: blockTime,
port: port,
blobs: make(map[uint64][]*kzg4844.Blob),
}
}

Expand All @@ -59,13 +55,21 @@ func (f *BeaconMock) Start(host string) error {

mux := new(http.ServeMux)
mux.HandleFunc("/eth/v1/beacon/genesis", func(w http.ResponseWriter, r *http.Request) {
err := json.NewEncoder(w).Encode(&ethadapter.APIGenesisResponse{Data: ethadapter.ReducedGenesisData{GenesisTime: ethadapter.Uint64String(f.genesisTime)}})
err := json.NewEncoder(w).Encode(&ethadapter.APIGenesisResponse{
Data: ethadapter.ReducedGenesisData{
GenesisTime: ethadapter.Uint64String(f.genesisTime),
},
})
if err != nil {
f.log.Error("genesis handler err", "err", err)
}
})
mux.HandleFunc("/eth/v1/config/spec", func(w http.ResponseWriter, r *http.Request) {
err := json.NewEncoder(w).Encode(&ethadapter.APIConfigResponse{Data: ethadapter.ReducedConfigData{SecondsPerSlot: ethadapter.Uint64String(f.blockTime)}})
err := json.NewEncoder(w).Encode(&ethadapter.APIConfigResponse{
Data: ethadapter.ReducedConfigData{
SecondsPerSlot: ethadapter.Uint64String(f.blockTime),
},
})
if err != nil {
f.log.Error("config handler err", "err", err)
}
Expand All @@ -78,22 +82,22 @@ func (f *BeaconMock) Start(host string) error {
w.WriteHeader(http.StatusBadRequest)
return
}
bundle, err := f.LoadBlobsBundle(slot)
blobs, err := f.LoadBlobs(slot)
if errors.Is(err, ethereum.NotFound) {
f.log.Error("failed to load blobs bundle - not found", "slot", slot, "err", err)
f.log.Error("failed to load blobs - not found", "slot", slot, "err", err)
w.WriteHeader(http.StatusNotFound)
return
} else if err != nil {
f.log.Error("failed to load blobs bundle", "slot", slot, "err", err)
f.log.Error("failed to load blobs", "slot", slot, "err", err)
w.WriteHeader(http.StatusInternalServerError)
return
}

query := r.URL.Query()
rawIndices := query["indices"]
indices := make([]uint64, 0, len(bundle.Blobs))
indices := make([]uint64, 0, len(blobs))
if len(rawIndices) == 0 {
for i := range bundle.Blobs {
for i := range blobs {
indices = append(indices, uint64(i))
}
} else {
Expand All @@ -113,88 +117,69 @@ func (f *BeaconMock) Start(host string) error {
binary.LittleEndian.PutUint64(mockBeaconBlockRoot[32-8:], slot)
sidecars := make([]*ethadapter.APIBlobSidecar, len(indices))
for i, ix := range indices {
if ix >= uint64(len(bundle.Blobs)) {
if ix >= uint64(len(blobs)) {
f.log.Error("blob index from request is out of range", "url", r.URL)
w.WriteHeader(http.StatusBadRequest)
return
}

blob := blobs[ix]

commitment, err := kzg4844.BlobToCommitment(blob)
if err != nil {
f.log.Error("failed to compute KZG commitment", "blobIndex", ix, "err", err)
w.WriteHeader(http.StatusInternalServerError)
return
}

proof, err := kzg4844.ComputeBlobProof(blob, commitment)
if err != nil {
f.log.Error("failed to compute KZG proof", "blobIndex", ix, "err", err)
w.WriteHeader(http.StatusInternalServerError)
return
}

sidecars[i] = &ethadapter.APIBlobSidecar{
Index: ethadapter.Uint64String(ix),
KZGCommitment: ethadapter.Bytes48(bundle.Commitments[ix]),
KZGProof: ethadapter.Bytes48(bundle.Proofs[ix]),
Blob: *blob,
KZGCommitment: ethadapter.Bytes48(commitment[:]),
KZGProof: ethadapter.Bytes48(proof[:]),
SignedBlockHeader: ethadapter.SignedBeaconBlockHeader{
Message: ethadapter.BeaconBlockHeader{
StateRoot: mockBeaconBlockRoot,
Slot: ethadapter.Uint64String(slot),
},
},
}
copy(sidecars[i].Blob[:], bundle.Blobs[ix])
}
if err := json.NewEncoder(w).Encode(&ethadapter.APIGetBlobSidecarsResponse{Data: sidecars}); err != nil {
f.log.Error("blobs handler err", "err", err)
}
})
mux.HandleFunc("/eth/v1/node/version", func(w http.ResponseWriter, r *http.Request) {
err := json.NewEncoder(w).Encode(&ethadapter.APIVersionResponse{Data: ethadapter.VersionInformation{Version: "BeaconMock 1.2.3"}})
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
f.log.Error("version handler err", "err", err)
} else {
w.WriteHeader(http.StatusOK)
}
})
f.beaconSrv = &http.Server{
Handler: mux,
ReadTimeout: time.Second * 20,
ReadHeaderTimeout: time.Second * 20,
WriteTimeout: time.Second * 20,
IdleTimeout: time.Second * 20,
}
go func() {
if err := f.beaconSrv.Serve(f.beaconAPIListener); err != nil && !errors.Is(err, http.ErrServerClosed) {
f.log.Error("failed to start fake-pos beacon server for blobs testing", "err", err)
}
}()
return nil
}

func (f *BeaconMock) StoreBlobsBundle(slot uint64, bundle *engine.BlobsBundleV1) error {
data, err := json.Marshal(bundle)
if err != nil {
return fmt.Errorf("failed to encode blobs bundle of slot %d: %w", slot, err)
}

// StoreBlobs stores the array of blobs against the slot number.
func (f *BeaconMock) StoreBlobs(slot uint64, blobs []*kzg4844.Blob) error {
f.blobsLock.Lock()
defer f.blobsLock.Unlock()
bundlePath := fmt.Sprintf("blobs_bundle_%d.json", slot)
if err := os.MkdirAll(f.blobsDir, 0755); err != nil {
return fmt.Errorf("failed to create dir for blob storage: %w", err)
}
err = os.WriteFile(filepath.Join(f.blobsDir, bundlePath), data, 0755)
if err != nil {
return fmt.Errorf("failed to write blobs bundle of slot %d: %w", slot, err)

if len(blobs) > 0 {
f.blobs[slot] = blobs
}
return nil
}

func (f *BeaconMock) LoadBlobsBundle(slot uint64) (*engine.BlobsBundleV1, error) {
// LoadBlobs retrieves the array of blobs for a given slot.
func (f *BeaconMock) LoadBlobs(slot uint64) ([]*kzg4844.Blob, error) {
f.blobsLock.Lock()
defer f.blobsLock.Unlock()
bundlePath := fmt.Sprintf("blobs_bundle_%d.json", slot)
data, err := os.ReadFile(filepath.Join(f.blobsDir, bundlePath))
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("no blobs bundle found for slot %d (%q): %w", slot, bundlePath, ethereum.NotFound)
} else {
return nil, fmt.Errorf("failed to read blobs bundle of slot %d (%q): %w", slot, bundlePath, err)
}
}
var out engine.BlobsBundleV1
if err := json.Unmarshal(data, &out); err != nil {
return nil, fmt.Errorf("failed to decode blobs bundle of slot %d (%q): %w", slot, bundlePath, err)

blobs, exists := f.blobs[slot]
if !exists {
return nil, fmt.Errorf("no blobs found for slot %d: %w", slot, ethereum.NotFound)
}
return &out, nil
return blobs, nil
}

func (f *BeaconMock) Close() error {
Expand Down
4 changes: 2 additions & 2 deletions integration/ethereummock/beacon_client_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func TestGetVersion(t *testing.T) {
l := testlog.Logger()

beaconApi := NewBeaconMock(l, t.TempDir(), uint64(1), uint64(1), 8000)
beaconApi := NewBeaconMock(l, uint64(1), uint64(1), 8000)
t.Cleanup(func() {
_ = beaconApi.Close()
})
Expand All @@ -29,7 +29,7 @@ func TestGetVersion(t *testing.T) {
func Test404NotFound(t *testing.T) {
l := testlog.Logger()

beaconApi := NewBeaconMock(l, t.TempDir(), uint64(1), uint64(12), 8000)
beaconApi := NewBeaconMock(l, uint64(1), uint64(12), 8000)
t.Cleanup(func() {
_ = beaconApi.Close()
})
Expand Down
Loading
Loading