From 41a340bf7fcb7f1f1ca936b50bad968b4ed904db Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 1 Dec 2023 10:33:26 +0800 Subject: [PATCH 1/9] remove useless code --- ethstorage/node/node.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ethstorage/node/node.go b/ethstorage/node/node.go index 26c0c86e..15817513 100644 --- a/ethstorage/node/node.go +++ b/ethstorage/node/node.go @@ -30,10 +30,9 @@ type EsNode struct { appVersion string metrics metrics.Metricer - l1HeadsSub ethereum.Subscription // Subscription to get L1 heads (automatically re-subscribes on error) - l1SafeSub ethereum.Subscription // Subscription to get L1 safe blocks, a.k.a. justified data (polling) - l1FinalizedSub ethereum.Subscription // Subscription to get L1 Finalized blocks, a.k.a. justified data (polling) - l1LatestBlockSub ethereum.Subscription // Subscription to get L1 latest blocks, a.k.a. justified data (polling) + l1HeadsSub ethereum.Subscription // Subscription to get L1 heads (automatically re-subscribes on error) + l1SafeSub ethereum.Subscription // Subscription to get L1 safe blocks, a.k.a. justified data (polling) + l1FinalizedSub ethereum.Subscription // Subscription to get L1 Finalized blocks, a.k.a. justified data (polling) l1Source *eth.PollingClient // L1 Client to fetch data from l1Beacon *eth.BeaconClient // L1 Beacon Chain to fetch blobs from From a000a44432a83a8d269224ad4964f20c2515ad4e Mon Sep 17 00:00:00 2001 From: pingke Date: Thu, 14 Dec 2023 09:44:16 +0800 Subject: [PATCH 2/9] fix bug --- ethstorage/node/node_mine_test.go | 3 ++- ethstorage/node/node_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ethstorage/node/node_mine_test.go b/ethstorage/node/node_mine_test.go index 76be5f1d..3c4abae2 100644 --- a/ethstorage/node/node_mine_test.go +++ b/ethstorage/node/node_mine_test.go @@ -25,6 +25,7 @@ import ( es "github.com/ethstorage/go-ethstorage/ethstorage" "github.com/ethstorage/go-ethstorage/ethstorage/eth" esLog "github.com/ethstorage/go-ethstorage/ethstorage/log" + "github.com/ethstorage/go-ethstorage/ethstorage/metrics" "github.com/ethstorage/go-ethstorage/ethstorage/miner" "github.com/ethstorage/go-ethstorage/ethstorage/p2p/protocol" "github.com/ethstorage/go-ethstorage/ethstorage/signer" @@ -141,7 +142,7 @@ func TestMining(t *testing.T) { L1EpochPollInterval: time.Second * 10, Mining: miningConfig, } - n, err := New(context.Background(), cfg, l, "") + n, err := New(context.Background(), cfg, l, "", metrics.NoopMetrics) if err != nil { t.Fatalf("Create new node failed %v", err) } diff --git a/ethstorage/node/node_test.go b/ethstorage/node/node_test.go index b46145a9..ccb77e79 100644 --- a/ethstorage/node/node_test.go +++ b/ethstorage/node/node_test.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethstorage/go-ethstorage/ethstorage" "github.com/ethstorage/go-ethstorage/ethstorage/db" + "github.com/ethstorage/go-ethstorage/ethstorage/metrics" "github.com/ethstorage/go-ethstorage/ethstorage/storage" ) @@ -54,7 +55,7 @@ func test_InitDB(test *testing.T, dataDir string) { Storage: storConfig, } - n, err := New(context.Background(), &cfg, nil, "") + n, err := New(context.Background(), &cfg, nil, "", metrics.NoopMetrics) if err != nil { test.Error(err.Error()) } From 218fd8620332f6c22258a968192ea591d24b6d54 Mon Sep 17 00:00:00 2001 From: pingke Date: Thu, 21 Dec 2023 15:38:19 +0800 Subject: [PATCH 3/9] update time unit from second to millisecond --- ethstorage/metrics/metrics.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ethstorage/metrics/metrics.go b/ethstorage/metrics/metrics.go index b0b1dac2..238db130 100644 --- a/ethstorage/metrics/metrics.go +++ b/ethstorage/metrics/metrics.go @@ -436,37 +436,37 @@ func (m *Metrics) SetPeerScores(scores map[string]float64) { func (m *Metrics) ClientGetBlobsByRangeEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncClientRequestsTotal.WithLabelValues("get_blobs_by_range", code).Inc() - m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(float64(duration) / float64(time.Second)) + m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) m.SyncClientPeerRequestsTotal.WithLabelValues(peerID, "get_blobs_by_range", code).Inc() - m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(float64(duration) / float64(time.Second)) + m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) } func (m *Metrics) ClientGetBlobsByListEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncClientRequestsTotal.WithLabelValues("get_blobs_by_list", code).Inc() - m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(float64(duration) / float64(time.Second)) + m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) m.SyncClientPeerRequestsTotal.WithLabelValues(peerID, "get_blobs_by_list", code).Inc() - m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(float64(duration) / float64(time.Second)) + m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) } func (m *Metrics) ClientFillEmptyBlobsEvent(count uint64, duration time.Duration) { method := "fillEmpty" m.SyncClientPerfCallTotal.WithLabelValues(method).Add(float64(count)) - m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Second) / float64(count)) + m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Millisecond) / float64(count)) } -func (m *Metrics) ClientOnBlobsByRange(peerID string, reqBlobCount, retBlobCount, insertedCount uint64, duration time.Duration) { +func (m *Metrics) ClientOnBlobsByRange(peerID string, reqBlobCount, getBlobCount, insertedCount uint64, duration time.Duration) { m.SyncClientState.WithLabelValues("reqBlobCount").Add(float64(reqBlobCount)) - m.SyncClientState.WithLabelValues("retBlobCount").Add(float64(retBlobCount)) + m.SyncClientState.WithLabelValues("getBlobCount").Add(float64(getBlobCount)) m.SyncClientState.WithLabelValues("insertedBlobCount").Add(float64(insertedCount)) m.SyncClientPeerState.WithLabelValues(peerID, "reqBlobCount").Add(float64(reqBlobCount)) - m.SyncClientPeerState.WithLabelValues(peerID, "retBlobCount").Add(float64(retBlobCount)) + m.SyncClientPeerState.WithLabelValues(peerID, "getBlobCount").Add(float64(getBlobCount)) m.SyncClientPeerState.WithLabelValues(peerID, "insertedBlobCount").Add(float64(insertedCount)) method := "onBlobsByRange" m.SyncClientPerfCallTotal.WithLabelValues(method).Inc() - m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Second)) + m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Millisecond)) } func (m *Metrics) ClientOnBlobsByList(peerID string, reqCount, retBlobCount, insertedCount uint64, duration time.Duration) { @@ -480,7 +480,7 @@ func (m *Metrics) ClientOnBlobsByList(peerID string, reqCount, retBlobCount, ins method := "onBlobsByList" m.SyncClientPerfCallTotal.WithLabelValues(method).Inc() - m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Second)) + m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Millisecond)) } func (m *Metrics) ClientRecordTimeUsed(method string) func() { @@ -506,19 +506,19 @@ func (m *Metrics) DecPeerCount() { func (m *Metrics) ServerGetBlobsByRangeEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncServerHandleReqTotal.WithLabelValues("get_blobs_by_range", code).Inc() - m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(float64(duration) / float64(time.Second)) + m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) m.SyncServerHandleReqTotalPerPeer.WithLabelValues(peerID, "get_blobs_by_range", code).Inc() - m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(float64(duration) / float64(time.Second)) + m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) } func (m *Metrics) ServerGetBlobsByListEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncServerHandleReqTotal.WithLabelValues("get_blobs_by_list", code).Inc() - m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(float64(duration) / float64(time.Second)) + m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) m.SyncServerHandleReqTotalPerPeer.WithLabelValues(peerID, "get_blobs_by_list", code).Inc() - m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(float64(duration) / float64(time.Second)) + m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) } func (m *Metrics) ServerReadBlobs(peerID string, read, sucRead uint64, timeUse time.Duration) { @@ -529,7 +529,7 @@ func (m *Metrics) ServerReadBlobs(peerID string, read, sucRead uint64, timeUse t method := "readBlobs" m.SyncServerPerfCallTotal.WithLabelValues(method).Inc() - m.SyncServerPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(timeUse) / float64(time.Second)) + m.SyncServerPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(timeUse) / float64(time.Millisecond)) } func (m *Metrics) ServerRecordTimeUsed(method string) func() { From 3235ba1e837af7a399035b7254b3e8ea615f6895 Mon Sep 17 00:00:00 2001 From: pingke Date: Thu, 21 Dec 2023 18:59:24 +0800 Subject: [PATCH 4/9] update unit --- ethstorage/metrics/metrics.go | 38 +++++++++++++-------------- ethstorage/p2p/protocol/syncclient.go | 4 ++- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/ethstorage/metrics/metrics.go b/ethstorage/metrics/metrics.go index 238db130..e6e9aab6 100644 --- a/ethstorage/metrics/metrics.go +++ b/ethstorage/metrics/metrics.go @@ -33,8 +33,8 @@ type Metricer interface { ClientGetBlobsByRangeEvent(peerID string, resultCode byte, duration time.Duration) ClientGetBlobsByListEvent(peerID string, resultCode byte, duration time.Duration) ClientFillEmptyBlobsEvent(count uint64, duration time.Duration) - ClientOnBlobsByRange(peerID string, reqCount, retBlobCount, insertedCount uint64, duration time.Duration) - ClientOnBlobsByList(peerID string, reqCount, retBlobCount, insertedCount uint64, duration time.Duration) + ClientOnBlobsByRange(peerID string, reqCount, getBlobCount, insertedCount uint64, duration time.Duration) + ClientOnBlobsByList(peerID string, reqCount, getBlobCount, insertedCount uint64, duration time.Duration) ClientRecordTimeUsed(method string) func() IncDropPeerCount() IncPeerCount() @@ -436,23 +436,23 @@ func (m *Metrics) SetPeerScores(scores map[string]float64) { func (m *Metrics) ClientGetBlobsByRangeEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncClientRequestsTotal.WithLabelValues("get_blobs_by_range", code).Inc() - m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(duration.Seconds()) m.SyncClientPeerRequestsTotal.WithLabelValues(peerID, "get_blobs_by_range", code).Inc() - m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(duration.Seconds()) } func (m *Metrics) ClientGetBlobsByListEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncClientRequestsTotal.WithLabelValues("get_blobs_by_list", code).Inc() - m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncClientRequestDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(duration.Seconds()) m.SyncClientPeerRequestsTotal.WithLabelValues(peerID, "get_blobs_by_list", code).Inc() - m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncClientPeerRequestDurationSeconds.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(duration.Seconds()) } func (m *Metrics) ClientFillEmptyBlobsEvent(count uint64, duration time.Duration) { method := "fillEmpty" m.SyncClientPerfCallTotal.WithLabelValues(method).Add(float64(count)) - m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Millisecond) / float64(count)) + m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(duration.Seconds() / float64(count)) } func (m *Metrics) ClientOnBlobsByRange(peerID string, reqBlobCount, getBlobCount, insertedCount uint64, duration time.Duration) { @@ -466,21 +466,21 @@ func (m *Metrics) ClientOnBlobsByRange(peerID string, reqBlobCount, getBlobCount method := "onBlobsByRange" m.SyncClientPerfCallTotal.WithLabelValues(method).Inc() - m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(duration.Seconds()) } -func (m *Metrics) ClientOnBlobsByList(peerID string, reqCount, retBlobCount, insertedCount uint64, duration time.Duration) { +func (m *Metrics) ClientOnBlobsByList(peerID string, reqCount, getBlobCount, insertedCount uint64, duration time.Duration) { m.SyncClientState.WithLabelValues("reqBlobCount").Add(float64(reqCount)) - m.SyncClientState.WithLabelValues("retBlobCount").Add(float64(retBlobCount)) + m.SyncClientState.WithLabelValues("getBlobCount").Add(float64(getBlobCount)) m.SyncClientState.WithLabelValues("insertedBlobCount").Add(float64(insertedCount)) m.SyncClientPeerState.WithLabelValues(peerID, "reqBlobCount").Add(float64(reqCount)) - m.SyncClientPeerState.WithLabelValues(peerID, "retBlobCount").Add(float64(retBlobCount)) + m.SyncClientPeerState.WithLabelValues(peerID, "getBlobCount").Add(float64(getBlobCount)) m.SyncClientPeerState.WithLabelValues(peerID, "insertedBlobCount").Add(float64(insertedCount)) method := "onBlobsByList" m.SyncClientPerfCallTotal.WithLabelValues(method).Inc() - m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncClientPerfCallDurationSeconds.WithLabelValues(method).Observe(duration.Seconds()) } func (m *Metrics) ClientRecordTimeUsed(method string) func() { @@ -506,19 +506,19 @@ func (m *Metrics) DecPeerCount() { func (m *Metrics) ServerGetBlobsByRangeEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncServerHandleReqTotal.WithLabelValues("get_blobs_by_range", code).Inc() - m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_range", code).Observe(duration.Seconds()) m.SyncServerHandleReqTotalPerPeer.WithLabelValues(peerID, "get_blobs_by_range", code).Inc() - m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_range", code).Observe(duration.Seconds()) } func (m *Metrics) ServerGetBlobsByListEvent(peerID string, resultCode byte, duration time.Duration) { code := strconv.FormatUint(uint64(resultCode), 10) m.SyncServerHandleReqTotal.WithLabelValues("get_blobs_by_list", code).Inc() - m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncServerHandleReqDurationSeconds.WithLabelValues("get_blobs_by_list", code).Observe(duration.Seconds()) m.SyncServerHandleReqTotalPerPeer.WithLabelValues(peerID, "get_blobs_by_list", code).Inc() - m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(float64(duration) / float64(time.Millisecond)) + m.SyncServerHandleReqDurationSecondsPerPeer.WithLabelValues(peerID, "get_blobs_by_list", code).Observe(duration.Seconds()) } func (m *Metrics) ServerReadBlobs(peerID string, read, sucRead uint64, timeUse time.Duration) { @@ -529,7 +529,7 @@ func (m *Metrics) ServerReadBlobs(peerID string, read, sucRead uint64, timeUse t method := "readBlobs" m.SyncServerPerfCallTotal.WithLabelValues(method).Inc() - m.SyncServerPerfCallDurationSeconds.WithLabelValues(method).Observe(float64(timeUse) / float64(time.Millisecond)) + m.SyncServerPerfCallDurationSeconds.WithLabelValues(method).Observe(timeUse.Seconds()) } func (m *Metrics) ServerRecordTimeUsed(method string) func() { @@ -579,11 +579,11 @@ func (n *noopMetricer) ClientGetBlobsByListEvent(peerID string, resultCode byte, func (n *noopMetricer) ClientFillEmptyBlobsEvent(count uint64, duration time.Duration) { } -func (n *noopMetricer) ClientOnBlobsByRange(peerID string, reqCount, retBlobCount, insertedCount uint64, duration time.Duration) { +func (n *noopMetricer) ClientOnBlobsByRange(peerID string, reqCount, getBlobCount, insertedCount uint64, duration time.Duration) { } -func (n *noopMetricer) ClientOnBlobsByList(peerID string, reqCount, retBlobCount, insertedCount uint64, duration time.Duration) { +func (n *noopMetricer) ClientOnBlobsByList(peerID string, reqCount, getBlobCount, insertedCount uint64, duration time.Duration) { } func (n *noopMetricer) ClientRecordTimeUsed(method string) func() { diff --git a/ethstorage/p2p/protocol/syncclient.go b/ethstorage/p2p/protocol/syncclient.go index 82414cd0..66a77980 100644 --- a/ethstorage/p2p/protocol/syncclient.go +++ b/ethstorage/p2p/protocol/syncclient.go @@ -1016,13 +1016,15 @@ func (s *SyncClient) FillFileWithEmptyBlob(start, limit uint64) (uint64, error) inserted = uint64(0) next = start ) - defer s.metrics.ClientFillEmptyBlobsEvent(inserted, time.Since(st)) lastBlobIdx := s.storageManager.LastKvIndex() if start < lastBlobIdx { start = lastBlobIdx } inserted, next, err := s.storageManager.CommitEmptyBlobs(start, limit) + if inserted > 0 { + s.metrics.ClientFillEmptyBlobsEvent(inserted, time.Since(st)) + } return next, err } From 0d7680dfdfc2b7ce401a41755b7ef1033b01fe71 Mon Sep 17 00:00:00 2001 From: pingke Date: Fri, 22 Dec 2023 09:45:46 +0800 Subject: [PATCH 5/9] remove useless code --- ethstorage/node/node_mine_test.go | 293 ------------------------------ 1 file changed, 293 deletions(-) delete mode 100644 ethstorage/node/node_mine_test.go diff --git a/ethstorage/node/node_mine_test.go b/ethstorage/node/node_mine_test.go deleted file mode 100644 index 3c4abae2..00000000 --- a/ethstorage/node/node_mine_test.go +++ /dev/null @@ -1,293 +0,0 @@ -// Copyright 2022-2023, EthStorage. -// For license information, see https://github.com/ethstorage/es-node/blob/main/LICENSE - -//go:build !ci - -package node - -import ( - "context" - "fmt" - "io" - "net/http" - "os" - "os/signal" - "path/filepath" - "strings" - "syscall" - "testing" - "time" - - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/log" - "github.com/ethstorage/go-ethstorage/cmd/es-utils/utils" - es "github.com/ethstorage/go-ethstorage/ethstorage" - "github.com/ethstorage/go-ethstorage/ethstorage/eth" - esLog "github.com/ethstorage/go-ethstorage/ethstorage/log" - "github.com/ethstorage/go-ethstorage/ethstorage/metrics" - "github.com/ethstorage/go-ethstorage/ethstorage/miner" - "github.com/ethstorage/go-ethstorage/ethstorage/p2p/protocol" - "github.com/ethstorage/go-ethstorage/ethstorage/signer" - "github.com/ethstorage/go-ethstorage/ethstorage/storage" - "golang.org/x/term" -) - -const ( - rpcUrl = "http://65.108.236.27:8545" - chainID = "7011893058" - kvEntriesPerShard = 16 - kvSize = 128 * 1024 - chunkSize = 128 * 1024 - maxBlobsPerTx = 4 - dataFileName = "shard-%d.dat" -) - -var ( - minerAddr = common.HexToAddress("0x04580493117292ba13361D8e9e28609ec112264D") - contractAddr = common.HexToAddress("0x188aac000e21ec314C5694bB82035b72210315A8") - private = "95eb6ffd2ae0b115db4d1f0d58388216f9d026896696a5211d77b5f14eb5badf" - shardIds = []uint64{0, 1} - l = esLog.NewLogger(esLog.CLIConfig{ - Level: "info", - Format: "text", - Color: term.IsTerminal(int(os.Stdout.Fd())), - }) -) - -// to use a new contract and override data files: -// go test -run ^TestMining$ github.com/ethstorage/go-ethstorage/ethstorage/node -v count=1 -contract=0x9BE8dEbb712A3c0dD163Da85D3aF867793Aef3E6 -init=true -func TestMining(t *testing.T) { - contract := contractAddr - flagContract := getArg("-contract") - if flagContract != "" { - contract = common.HexToAddress(flagContract) - l.Info("Use the contract address from flag", "contract", flagContract) - } - init := false - flagInitStorage := getArg("-init") - if flagInitStorage == "true" { - l.Info("Data files will be removed") - init = true - } - - intialized := false - existFile := 0 - for _, shardId := range shardIds { - fileName := fmt.Sprintf(dataFileName, shardId) - if _, err := os.Stat(fileName); !os.IsNotExist(err) { - if init { - os.Remove(fileName) - } else { - existFile++ - } - } - } - - if existFile == 2 { - intialized = true - l.Info("Data files already exist, will start mining") - } - if existFile == 1 { - l.Crit("One of the data files is missing, please check") - } - if existFile == 0 { - l.Info("Will initialize the data files, please make sure you use a new contract") - } - storConfig := storage.StorageConfig{ - KvSize: kvSize, - ChunkSize: chunkSize, - KvEntriesPerShard: kvEntriesPerShard, - L1Contract: contract, - Miner: minerAddr, - } - var files []string - if !intialized { - f, err := CreateDataFiles(&storConfig) - if err != nil { - t.Fatalf("Create data files error: %v", err) - } - files = f - } else { - for _, shardIdx := range shardIds { - fileName := fmt.Sprintf(dataFileName, shardIdx) - files = append(files, fileName) - } - } - storConfig.Filenames = files - - signerCfg := signer.CLIConfig{ - // Endpoint: "http://65.108.236.27:8550", - // Address: "0x13259366de990b0431e2c97cea949362bb68df12", - PrivateKey: private, - } - factory, addrFrom, err := signer.SignerFactoryFromConfig(signerCfg) - if err != nil { - t.Fatal("SignerFactoryFromConfig err", err) - } - miningConfig := &miner.DefaultConfig - miningConfig.SignerFnFactory = factory - miningConfig.SignerAddr = addrFrom - zkWorkingDir, err := filepath.Abs("../prover") - if err != nil { - t.Fatalf("Get zkWorkingDir error: %v", err) - } - miningConfig.ZKWorkingDir = zkWorkingDir - l1 := ð.L1EndpointConfig{ - L1NodeAddr: rpcUrl, - } - cfg := &Config{ - Storage: storConfig, - L1: *l1, - L1EpochPollInterval: time.Second * 10, - Mining: miningConfig, - } - n, err := New(context.Background(), cfg, l, "", metrics.NoopMetrics) - if err != nil { - t.Fatalf("Create new node failed %v", err) - } - - if !intialized { - // prepareData(t, n, contract) - fillEmpty(t, n, contract) - } - n.startL1(cfg) - n.miner.Start() - n.feed.Send(protocol.EthStorageSyncDone{ - DoneType: protocol.SingleShardDone, - ShardId: 0, - }) - time.Sleep(360 * time.Second) - n.feed.Send(protocol.EthStorageSyncDone{ - DoneType: protocol.SingleShardDone, - ShardId: 1, - }) - - c := make(chan os.Signal) - signal.Notify(c, os.Interrupt, syscall.SIGTERM) - <-c - n.miner.Close() -} - -func getArg(paramName string) string { - for _, arg := range os.Args { - pair := strings.Split(arg, "=") - if len(pair) == 2 && pair[0] == paramName { - paramValue := pair[1] - fmt.Printf("%s=%s\n", paramName, paramValue) - return paramValue - } - } - return "" -} - -func fillEmpty(t *testing.T, n *EsNode, contract common.Address) { - empty := make([]byte, 0) - block, err := n.l1Source.BlockNumber(context.Background()) - if err != nil { - t.Fatalf("Failed to get block number %v", err) - } - n.storageManager.Reset(int64(block)) - lastBlobIdx := n.storageManager.LastKvIndex() - limit := n.storageManager.KvEntries() * uint64(len(shardIds)) - for idx := lastBlobIdx; idx < limit; idx++ { - err = n.storageManager.CommitBlob(idx, empty, common.Hash{}) - if err != nil { - t.Fatalf("write empty to kv file fail, index: %d; error: %s", idx, err.Error()) - } - } -} - -func prepareData(t *testing.T, n *EsNode, contract common.Address) { - data, err := getSourceData() - if err != nil { - t.Fatalf("Get source data failed %v", err) - } - blobs := utils.EncodeBlobs(data) - t.Logf("Blobs len %d \n", len(blobs)) - var hashs []common.Hash - var ids []uint64 - - value := hexutil.EncodeUint64(10000000000000) - txs := len(blobs) / maxBlobsPerTx - last := len(blobs) % maxBlobsPerTx - if last > 0 { - txs = txs + 1 - } - t.Logf("tx len %d \n", txs) - for i := 0; i < txs; i++ { - max := maxBlobsPerTx - if i == txs-1 { - max = last - } - blobGroup := blobs[i*maxBlobsPerTx : i*maxBlobsPerTx+max] - var blobData []byte - for _, bd := range blobGroup { - blobData = append(blobData, bd[:]...) - } - if len(blobData) == 0 { - break - } - kvIdxes, dataHashes, err := utils.UploadBlobs(n.l1Source, rpcUrl, private, chainID, contract, blobData, false, value) - if err != nil { - t.Fatalf("Upload blobs failed %v", err) - } - hashs = append(hashs, dataHashes...) - ids = append(ids, kvIdxes...) - t.Logf("ids=%v \n", ids) - } - block, err := n.l1Source.BlockNumber(context.Background()) - if err != nil { - t.Fatalf("Failed to get block number %v", err) - } - n.storageManager.Reset(int64(block)) - for i := 0; i < len(shardIds)*kvEntriesPerShard; i++ { - err := n.storageManager.CommitBlob(ids[i], blobs[i][:], hashs[i]) - if err != nil { - t.Fatalf("Failed to commit blob: id %d, error: %v", ids[i], err) - } - } -} - -func CreateDataFiles(cfg *storage.StorageConfig) ([]string, error) { - var files []string - for _, shardIdx := range shardIds { - fileName := fmt.Sprintf(dataFileName, shardIdx) - if _, err := os.Stat(fileName); err == nil { - l.Crit("Creating data file", "error", "file already exists, will not overwrite", "file", fileName) - } - if cfg.ChunkSize == 0 { - l.Crit("Creating data file", "error", "chunk size should not be 0") - } - if cfg.KvSize%cfg.ChunkSize != 0 { - l.Crit("Creating data file", "error", "max kv size %% chunk size should be 0") - } - chunkPerKv := cfg.KvSize / cfg.ChunkSize - startChunkId := shardIdx * cfg.KvEntriesPerShard * chunkPerKv - chunkIdxLen := chunkPerKv * cfg.KvEntriesPerShard - log.Info("Creating data file", "chunkIdxStart", startChunkId, "chunkIdxLen", chunkIdxLen, "chunkSize", cfg.ChunkSize, "miner", cfg.Miner, "encodeType", es.ENCODE_BLOB_POSEIDON) - - df, err := es.Create(fileName, startChunkId, chunkPerKv*cfg.KvEntriesPerShard, 0, cfg.KvSize, es.ENCODE_BLOB_POSEIDON, cfg.Miner, cfg.ChunkSize) - if err != nil { - log.Crit("Creating data file", "error", err) - } - - l.Info("Data file created", "shard", shardIdx, "file", fileName, "datafile", fmt.Sprintf("%+v", df)) - files = append(files, fileName) - } - return files, nil -} - -func getSourceData() ([]byte, error) { - txt_4m := "https://www.gutenberg.org/cache/epub/10/pg10.txt" - resp, err := http.Get(txt_4m) - if err != nil { - return nil, fmt.Errorf("error reading blob txtUrl: %v", err) - } - defer resp.Body.Close() - data, err := io.ReadAll(resp.Body) - if err != nil { - return nil, fmt.Errorf("error reading blob txtUrl: %v", err) - } - return data, nil -} From 32cbc8ed9b3980751c86ede0a7308c3a217babe0 Mon Sep 17 00:00:00 2001 From: pingke Date: Mon, 25 Dec 2023 17:30:50 +0800 Subject: [PATCH 6/9] fix ut build --- ethstorage/p2p/protocol/sync_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethstorage/p2p/protocol/sync_test.go b/ethstorage/p2p/protocol/sync_test.go index b3ece4b8..86edd4f3 100644 --- a/ethstorage/p2p/protocol/sync_test.go +++ b/ethstorage/p2p/protocol/sync_test.go @@ -1209,8 +1209,7 @@ func TestFillEmpty(t *testing.T) { shardMap = make(map[common.Address][]uint64) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: true, + L2ChainID: new(big.Int).SetUint64(3333), } ) From 484760ae615821690738abc7c16d22289a971817 Mon Sep 17 00:00:00 2001 From: pingke Date: Thu, 4 Jan 2024 19:11:16 +0800 Subject: [PATCH 7/9] change back --- cmd/es-node/config.go | 13 ++++++------ cmd/es-node/main.go | 9 +++++++- ethstorage/flags/flags.go | 24 ++++++++++++++++----- ethstorage/node/config.go | 28 +++++++++++++++++++++---- ethstorage/node/node.go | 31 +++++++++++++++++++++------- ethstorage/node/node_test.go | 2 ++ ethstorage/p2p/node.go | 2 +- ethstorage/p2p/protocol/sync_test.go | 21 +++++++------------ ethstorage/rollup/config.go | 3 +-- 9 files changed, 91 insertions(+), 42 deletions(-) diff --git a/cmd/es-node/config.go b/cmd/es-node/config.go index 11a6080f..65b816cc 100644 --- a/cmd/es-node/config.go +++ b/cmd/es-node/config.go @@ -90,11 +90,11 @@ func NewConfig(ctx *cli.Context, log log.Logger) (*node.Config, error) { ListenPort: ctx.GlobalInt(flags.RPCListenPort.Name), ESCallURL: ctx.GlobalString(flags.RPCESCallURL.Name), }, - // Metrics: node.MetricsConfig{ - // Enabled: ctx.GlobalBool(flags.MetricsEnabledFlag.Name), - // ListenAddr: ctx.GlobalString(flags.MetricsAddrFlag.Name), - // ListenPort: ctx.GlobalInt(flags.MetricsPortFlag.Name), - // }, + Metrics: node.MetricsConfig{ + Enabled: ctx.GlobalBool(flags.MetricsEnabledFlag.Name), + ListenAddr: ctx.GlobalString(flags.MetricsAddrFlag.Name), + ListenPort: ctx.GlobalInt(flags.MetricsPortFlag.Name), + }, Pprof: oppprof.CLIConfig{ Enabled: ctx.GlobalBool(flags.PprofEnabledFlag.Name), ListenAddr: ctx.GlobalString(flags.PprofAddrFlag.Name), @@ -212,8 +212,7 @@ func NewRollupConfig(ctx *cli.Context) (*rollup.EsConfig, error) { // return nil, err // } config := rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(ctx.GlobalUint64(flags.L2ChainId.Name)), - MetricsEnable: ctx.Bool(flags.MetricsEnable.Name), + L2ChainID: new(big.Int).SetUint64(ctx.GlobalUint64(flags.L2ChainId.Name)), } return &config, nil diff --git a/cmd/es-node/main.go b/cmd/es-node/main.go index 8914cad3..2614baca 100644 --- a/cmd/es-node/main.go +++ b/cmd/es-node/main.go @@ -22,6 +22,7 @@ import ( "github.com/ethstorage/go-ethstorage/ethstorage" "github.com/ethstorage/go-ethstorage/ethstorage/flags" eslog "github.com/ethstorage/go-ethstorage/ethstorage/log" + "github.com/ethstorage/go-ethstorage/ethstorage/metrics" "github.com/ethstorage/go-ethstorage/ethstorage/node" "github.com/urfave/cli" ) @@ -118,7 +119,11 @@ func EsNodeMain(ctx *cli.Context) error { return err } - n, err := node.New(context.Background(), cfg, log, VersionWithMeta) + var m metrics.Metricer = metrics.NoopMetrics + if cfg.Metrics.Enabled { + m = metrics.NewMetrics("default") + } + n, err := node.New(context.Background(), cfg, log, VersionWithMeta, m) if err != nil { log.Error("Unable to create the storage node", "error", err) return err @@ -131,6 +136,8 @@ func EsNodeMain(ctx *cli.Context) error { } defer n.Close() + m.RecordInfo(VersionWithMeta) + m.RecordUp() // TODO: heartbeat if cfg.Pprof.Enabled { pprofCtx, pprofCancel := context.WithCancel(context.Background()) diff --git a/ethstorage/flags/flags.go b/ethstorage/flags/flags.go index a36fa373..023ebdbb 100644 --- a/ethstorage/flags/flags.go +++ b/ethstorage/flags/flags.go @@ -82,10 +82,22 @@ var ( Value: 3333, EnvVar: prefixEnvVar("L2_CHAIN_ID"), } - MetricsEnable = cli.BoolFlag{ - Name: "metrics.enable", - Usage: "Enable metrics", - EnvVar: prefixEnvVar("METRICS_ENABLE"), + MetricsEnabledFlag = cli.BoolFlag{ + Name: "metrics.enabled", + Usage: "Enable the metrics server", + EnvVar: prefixEnvVar("METRICS_ENABLED"), + } + MetricsAddrFlag = cli.StringFlag{ + Name: "metrics.addr", + Usage: "Metrics listening address", + Value: "0.0.0.0", + EnvVar: prefixEnvVar("METRICS_ADDR"), + } + MetricsPortFlag = cli.IntFlag{ + Name: "metrics.port", + Usage: "Metrics listening port", + Value: 7300, + EnvVar: prefixEnvVar("METRICS_PORT"), } PprofEnabledFlag = cli.BoolFlag{ Name: "pprof.enabled", @@ -205,7 +217,9 @@ var optionalFlags = []cli.Flag{ L1BeaconSlotTime, L1MinDurationForBlobsRequest, L2ChainId, - MetricsEnable, + MetricsEnabledFlag, + MetricsAddrFlag, + MetricsPortFlag, PprofEnabledFlag, PprofAddrFlag, PprofPortFlag, diff --git a/ethstorage/node/config.go b/ethstorage/node/config.go index a9d57451..68f36bba 100644 --- a/ethstorage/node/config.go +++ b/ethstorage/node/config.go @@ -4,7 +4,9 @@ package node import ( + "errors" "fmt" + "math" "path/filepath" "time" @@ -41,7 +43,7 @@ type Config struct { Storage storage.StorageConfig - // Metrics MetricsConfig + Metrics MetricsConfig Pprof oppprof.CLIConfig @@ -54,6 +56,24 @@ type Config struct { Mining *miner.Config } +type MetricsConfig struct { + Enabled bool + ListenAddr string + ListenPort int +} + +func (m MetricsConfig) Check() error { + if !m.Enabled { + return nil + } + + if m.ListenPort < 0 || m.ListenPort > math.MaxUint16 { + return errors.New("invalid metrics port") + } + + return nil +} + type RPCConfig struct { ListenAddr string ListenPort int @@ -71,9 +91,9 @@ func (cfg *Config) Check() error { // if err := cfg.Rollup.Check(); err != nil { // return fmt.Errorf("rollup config error: %w", err) // } - // if err := cfg.Metrics.Check(); err != nil { - // return fmt.Errorf("metrics config error: %w", err) - // } + if err := cfg.Metrics.Check(); err != nil { + return fmt.Errorf("metrics config error: %w", err) + } if err := cfg.Pprof.Check(); err != nil { return fmt.Errorf("pprof config error: %w", err) } diff --git a/ethstorage/node/node.go b/ethstorage/node/node.go index 661bc48f..15817513 100644 --- a/ethstorage/node/node.go +++ b/ethstorage/node/node.go @@ -28,7 +28,7 @@ import ( type EsNode struct { log log.Logger appVersion string - metrics *metrics.Metrics + metrics metrics.Metricer l1HeadsSub ethereum.Subscription // Subscription to get L1 heads (automatically re-subscribes on error) l1SafeSub ethereum.Subscription // Subscription to get L1 safe blocks, a.k.a. justified data (polling) @@ -56,14 +56,15 @@ type EsNode struct { feed *event.Feed } -func New(ctx context.Context, cfg *Config, log log.Logger, appVersion string) (*EsNode, error) { - // if err := cfg.Check(); err != nil { - // return nil, err - // } +func New(ctx context.Context, cfg *Config, log log.Logger, appVersion string, m metrics.Metricer) (*EsNode, error) { + if err := cfg.Check(); err != nil { + return nil, err + } n := &EsNode{ log: log, appVersion: appVersion, + metrics: m, } // not a context leak, gossipsub is closed with a context. n.resourcesCtx, n.resourcesClose = context.WithCancel(context.Background()) @@ -113,9 +114,9 @@ func (n *EsNode) init(ctx context.Context, cfg *Config) error { if err := n.initRPCServer(ctx, cfg); err != nil { return err } - // if err := n.initMetricsServer(ctx, cfg); err != nil { - // return err - // } + if err := n.initMetricsServer(ctx, cfg); err != nil { + return err + } return nil } @@ -227,6 +228,20 @@ func (n *EsNode) initRPCServer(ctx context.Context, cfg *Config) error { return nil } +func (n *EsNode) initMetricsServer(ctx context.Context, cfg *Config) error { + if !cfg.Metrics.Enabled { + n.log.Info("Metrics disabled") + return nil + } + n.log.Info("Starting metrics server", "addr", cfg.Metrics.ListenAddr, "port", cfg.Metrics.ListenPort) + go func() { + if err := n.metrics.Serve(ctx, cfg.Metrics.ListenAddr, cfg.Metrics.ListenPort); err != nil { + log.Crit("Error starting metrics server", "err", err) + } + }() + return nil +} + func (n *EsNode) initMiner(ctx context.Context, cfg *Config) error { if cfg.Mining == nil { // not enabled diff --git a/ethstorage/node/node_test.go b/ethstorage/node/node_test.go index c7bf80d6..927f238f 100644 --- a/ethstorage/node/node_test.go +++ b/ethstorage/node/node_test.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethstorage/go-ethstorage/ethstorage" "github.com/ethstorage/go-ethstorage/ethstorage/db" + "github.com/ethstorage/go-ethstorage/ethstorage/metrics" "github.com/ethstorage/go-ethstorage/ethstorage/storage" ) @@ -54,6 +55,7 @@ func test_InitDB(test *testing.T, dataDir string) { n := &EsNode{ log: log.New("unittest"), appVersion: "unittest", + metrics: metrics.NoopMetrics, } err := n.initDatabase(&cfg) if err != nil { diff --git a/ethstorage/p2p/node.go b/ethstorage/p2p/node.go index 85d3dc38..2afebb65 100644 --- a/ethstorage/p2p/node.go +++ b/ethstorage/p2p/node.go @@ -178,7 +178,7 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.EsConfig, } if m != nil { - // go metrics.RecordBandwidth(resourcesCtx, bwc) + // go m.RecordBandwidth(resourcesCtx, bwc) } } return nil diff --git a/ethstorage/p2p/protocol/sync_test.go b/ethstorage/p2p/protocol/sync_test.go index 5bef669b..7485fef5 100644 --- a/ethstorage/p2p/protocol/sync_test.go +++ b/ethstorage/p2p/protocol/sync_test.go @@ -516,8 +516,7 @@ func TestSync_RequestL2Range(t *testing.T) { shards = make(map[common.Address][]uint64) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: false, + L2ChainID: new(big.Int).SetUint64(3333), } ) defer cancel() @@ -589,8 +588,7 @@ func TestSync_RequestL2List(t *testing.T) { shards = make(map[common.Address][]uint64) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: false, + L2ChainID: new(big.Int).SetUint64(3333), } ) defer cancel() @@ -664,8 +662,7 @@ func TestSaveAndLoadSyncStatus(t *testing.T) { m = metrics.NewMetrics("sync_test") expectedTimeUsed = time.Second * 10 rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: true, + L2ChainID: new(big.Int).SetUint64(3333), } ) // create ethstorage and generate data @@ -766,8 +763,7 @@ func testSync(t *testing.T, chunkSize, kvSize, kvEntries uint64, localShards []u localShardMap = make(map[common.Address][]uint64) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: true, + L2ChainID: new(big.Int).SetUint64(3333), } ) @@ -995,8 +991,7 @@ func TestAddPeerDuringSyncing(t *testing.T) { excludedList = getRandomU64InRange(make(map[uint64]struct{}), 0, 15, 3) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: true, + L2ChainID: new(big.Int).SetUint64(3333), } ) @@ -1078,8 +1073,7 @@ func TestCloseSyncWhileFillEmpty(t *testing.T) { shardMap = make(map[common.Address][]uint64) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: true, + L2ChainID: new(big.Int).SetUint64(3333), } ) @@ -1133,8 +1127,7 @@ func TestAddPeerAfterSyncDone(t *testing.T) { excludedList = make(map[uint64]struct{}) m = metrics.NewMetrics("sync_test") rollupCfg = &rollup.EsConfig{ - L2ChainID: new(big.Int).SetUint64(3333), - MetricsEnable: true, + L2ChainID: new(big.Int).SetUint64(3333), } ) diff --git a/ethstorage/rollup/config.go b/ethstorage/rollup/config.go index c1727936..1a9a40a2 100644 --- a/ethstorage/rollup/config.go +++ b/ethstorage/rollup/config.go @@ -3,8 +3,7 @@ package rollup import "math/big" type EsConfig struct { - L2ChainID *big.Int `json:"l2_chain_id"` - MetricsEnable bool `json:"metrics_enable"` + L2ChainID *big.Int `json:"l2_chain_id"` // Required to identify the L2 network and create p2p signatures unique for this chain. // L2ChainID *big.Int `json:"l2_chain_id"` } From 7e204b168525cd3d27ea7c9891cd62e1acaee828 Mon Sep 17 00:00:00 2001 From: Qiang Zhu Date: Thu, 4 Jan 2024 19:26:17 +0800 Subject: [PATCH 8/9] rpc use l2ChainId --- ethstorage/node/eth_api.go | 16 +++++++++------- ethstorage/node/node.go | 2 +- ethstorage/node/server.go | 4 +++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ethstorage/node/eth_api.go b/ethstorage/node/eth_api.go index 39b3be13..0b4271a9 100644 --- a/ethstorage/node/eth_api.go +++ b/ethstorage/node/eth_api.go @@ -5,6 +5,7 @@ package node import ( "context" + "math/big" "time" "github.com/ethereum/go-ethereum/common" @@ -15,12 +16,12 @@ import ( ) type ethAPI struct { - rpcCfg *RPCConfig - log log.Logger + rpcCfg *RPCConfig + chainId *big.Int + log log.Logger } const ( - ESChainID = 333 defaultCallTimeout = 2 * time.Second ) @@ -28,15 +29,16 @@ var ( rpcCli *rpc.Client ) -func NewETHAPI(config *RPCConfig, log log.Logger) *ethAPI { +func NewETHAPI(config *RPCConfig, chainId *big.Int, log log.Logger) *ethAPI { return ðAPI{ - rpcCfg: config, - log: log, + rpcCfg: config, + chainId: chainId, + log: log, } } func (api *ethAPI) ChainId() hexutil.Uint64 { - return hexutil.Uint64(ESChainID) + return hexutil.Uint64(api.chainId.Uint64()) } type TransactionArgs struct { diff --git a/ethstorage/node/node.go b/ethstorage/node/node.go index 0ad1df3c..926e4464 100644 --- a/ethstorage/node/node.go +++ b/ethstorage/node/node.go @@ -215,7 +215,7 @@ func (n *EsNode) initStorageManager(ctx context.Context, cfg *Config) error { } func (n *EsNode) initRPCServer(ctx context.Context, cfg *Config) error { - server, err := newRPCServer(ctx, &cfg.RPC, n.storageManager, n.downloader, n.log, n.appVersion) + server, err := newRPCServer(ctx, &cfg.RPC, cfg.Rollup.L2ChainID, n.storageManager, n.downloader, n.log, n.appVersion) if err != nil { return err } diff --git a/ethstorage/node/server.go b/ethstorage/node/server.go index 47ccc945..c40b380e 100644 --- a/ethstorage/node/server.go +++ b/ethstorage/node/server.go @@ -6,6 +6,7 @@ package node import ( "context" "errors" + "math/big" "net" "net/http" "strconv" @@ -30,13 +31,14 @@ type rpcServer struct { func newRPCServer( ctx context.Context, rpcCfg *RPCConfig, + l2ChainId *big.Int, sm *ethstorage.StorageManager, dl *downloader.Downloader, log log.Logger, appVersion string, ) (*rpcServer, error) { esAPI := NewESAPI(rpcCfg, sm, dl, log) - ethApi := NewETHAPI(rpcCfg, log) + ethApi := NewETHAPI(rpcCfg, l2ChainId, log) endpoint := net.JoinHostPort(rpcCfg.ListenAddr, strconv.Itoa(rpcCfg.ListenPort)) r := &rpcServer{ From ab07080830626e24001d752434f5bf611df0bd9e Mon Sep 17 00:00:00 2001 From: syntrust Date: Fri, 5 Jan 2024 14:42:28 +0800 Subject: [PATCH 9/9] check snarkjs --- run.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/run.sh b/run.sh index 28c43c80..c286e67d 100755 --- a/run.sh +++ b/run.sh @@ -23,6 +23,12 @@ if [ ${#ES_NODE_SIGNER_PRIVATE_KEY} -ne 64 ]; then exit 1 fi +# install snarkjs if not +if ! [ "$(command -v snarkjs)" ]; then + echo "snarkjs not found, start installing..." + npm install -g snarkjs +fi + # download blob_poseidon.zkey if not yet zkey_file="./build/bin/snarkjs/blob_poseidon.zkey" if [ ! -e ${zkey_file} ]; then