From 9274388e1f2f057eece08fdf6f86647f8985e7e5 Mon Sep 17 00:00:00 2001 From: nuxtreact Date: Fri, 13 Feb 2026 00:40:55 +0800 Subject: [PATCH] refactor: replace interface{} with any for clarity and modernization Signed-off-by: nuxtreact --- cmd/es-node/utils.go | 2 +- ethstorage/p2p/config.go | 3 +-- ethstorage/p2p/gossip.go | 4 +--- ethstorage/p2p/protocol/utils.go | 4 ++-- ethstorage/pora/ethash/ethash.go | 14 +++++++------- ethstorage/prover/utils.go | 2 +- integration_tests/kzg_prover_test.go | 4 ++-- integration_tests/zk_prover2_test.go | 4 ++-- integration_tests/zk_prover_test.go | 2 +- 9 files changed, 18 insertions(+), 21 deletions(-) diff --git a/cmd/es-node/utils.go b/cmd/es-node/utils.go index e89b96a2..5c06129b 100644 --- a/cmd/es-node/utils.go +++ b/cmd/es-node/utils.go @@ -164,7 +164,7 @@ func getDifficulty(ctx context.Context, client *ethclient.Client, contract commo return res[1].(*big.Int), nil } -func getMiningInfo(ctx context.Context, client *ethclient.Client, contract common.Address, shardIdx uint64) ([]interface{}, error) { +func getMiningInfo(ctx context.Context, client *ethclient.Client, contract common.Address, shardIdx uint64) ([]any, error) { uint256Type, _ := abi.NewType("uint256", "", nil) dataField, _ := abi.Arguments{{Type: uint256Type}}.Pack(new(big.Int).SetUint64(shardIdx)) h := crypto.Keccak256Hash([]byte(`infos(uint256)`)) diff --git a/ethstorage/p2p/config.go b/ethstorage/p2p/config.go index 82c1ddfa..8f61338d 100644 --- a/ethstorage/p2p/config.go +++ b/ethstorage/p2p/config.go @@ -28,8 +28,7 @@ var DefaultBootnodes = []*enode.Node{ enode.MustParse("enr:-J24QKTMozsV7vECSF7pqLAefTlVuMzWemnxIcdvsyIpfxWdFJxQs2Z7GnflniDpjeM_xjUpPO7gmsx6hOOIhHvnqimGAYfi6xtbimV0aHN0b3JhZ2XAgmlkgnY0gmlwhMCoAQKJc2VjcDI1NmsxoQN-8fpPc95ilMsRoMs1cRCi-s8kQrsT_cciktg_cUsuNYN0Y3CCJAaDdWRwgnZh"), } -type P2pSetupConfig interface { -} +type P2pSetupConfig any type GossipSetupConfigurables interface { PeerScoringParams() *pubsub.PeerScoreParams diff --git a/ethstorage/p2p/gossip.go b/ethstorage/p2p/gossip.go index 9a2c3a09..c79f8c68 100644 --- a/ethstorage/p2p/gossip.go +++ b/ethstorage/p2p/gossip.go @@ -41,9 +41,7 @@ const ( var MessageDomainInvalidSnappy = [4]byte{0, 0, 0, 0} var MessageDomainValidSnappy = [4]byte{1, 0, 0, 0} -type GossipIn interface { - // OnUnsafeL2Payload(ctx context.Context, from peer.ID, msg *eth.ExecutionPayload) error -} +type GossipIn any // TODO: func blocksTopicV1(chainID *big.Int) string { diff --git a/ethstorage/p2p/protocol/utils.go b/ethstorage/p2p/protocol/utils.go index 5fcdfb9e..c52b56c5 100644 --- a/ethstorage/p2p/protocol/utils.go +++ b/ethstorage/p2p/protocol/utils.go @@ -86,7 +86,7 @@ func ReadMsg(stream network.Stream) ([]byte, byte, error) { return payload, code, err } -func Send(stream network.Stream, req interface{}) (network.Stream, error) { +func Send(stream network.Stream, req any) (network.Stream, error) { data, err := rlp.EncodeToBytes(req) if err != nil { return nil, err @@ -105,7 +105,7 @@ func Send(stream network.Stream, req interface{}) (network.Stream, error) { return stream, err } -func SendRPC(stream network.Stream, req interface{}, resp interface{}) (byte, error) { +func SendRPC(stream network.Stream, req any, resp any) (byte, error) { s, err := Send(stream, req) if err != nil { return clientError, err diff --git a/ethstorage/pora/ethash/ethash.go b/ethstorage/pora/ethash/ethash.go index deab6a38..8fb7d295 100644 --- a/ethstorage/pora/ethash/ethash.go +++ b/ethstorage/pora/ethash/ethash.go @@ -149,24 +149,24 @@ func memoryMapAndGenerate(path string, size uint64, lock bool, generator func(bu // LRU tracks caches or datasets by their last use time, keeping at most N of them. type LRU struct { what string - new func(epoch uint64) interface{} + new func(epoch uint64) any mu sync.Mutex // Items are kept in a LRU cache, but there is a special case: // We always keep an item for (highest seen epoch) + 1 as the 'future item'. cache *simplelru.LRU future uint64 - futureItem interface{} + futureItem any lg log.Logger } // NewLRU create a new least-recently-used cache for either the verification caches // or the mining datasets. -func NewLRU(what string, maxItems int, new func(epoch uint64) interface{}) *LRU { +func NewLRU(what string, maxItems int, new func(epoch uint64) any) *LRU { if maxItems <= 0 { maxItems = 1 } lg := log.New("LRU") - cache, _ := simplelru.NewLRU(maxItems, func(key, value interface{}) { + cache, _ := simplelru.NewLRU(maxItems, func(key, value any) { lg.Trace("Evicted ethash "+what, "epoch", key) }) return &LRU{what: what, new: new, cache: cache, lg: lg} @@ -175,7 +175,7 @@ func NewLRU(what string, maxItems int, new func(epoch uint64) interface{}) *LRU // Get retrieves or creates an item for the given epoch. The first return value is always // non-nil. The second return value is non-nil if lru thinks that an item will be useful in // the near future. -func (lru *LRU) Get(epoch uint64) (item, future interface{}) { +func (lru *LRU) Get(epoch uint64) (item, future any) { lru.mu.Lock() defer lru.mu.Unlock() @@ -211,7 +211,7 @@ type Cache struct { // NewCache creates a new ethash verification cache and returns it as a plain Go // interface to be usable in an LRU cache. -func NewCache(epoch uint64) interface{} { +func NewCache(epoch uint64) any { return &Cache{epoch: epoch} } @@ -288,7 +288,7 @@ type dataset struct { // newDataset creates a new ethash mining dataset and returns it as a plain Go // interface to be usable in an LRU cache. -func newDataset(epoch uint64) interface{} { +func newDataset(epoch uint64) any { return &dataset{epoch: epoch} } diff --git a/ethstorage/prover/utils.go b/ethstorage/prover/utils.go index 8ccfef6c..61768bfb 100644 --- a/ethstorage/prover/utils.go +++ b/ethstorage/prover/utils.go @@ -190,7 +190,7 @@ func readProof(proofRaw []byte) ([]byte, error) { if err != nil { return nil, err } - values := []interface{}{[]*big.Int{a.X, a.Y}, [][]*big.Int{b.X[:], b.Y[:]}, []*big.Int{c.X, c.Y}} + values := []any{[]*big.Int{a.X, a.Y}, [][]*big.Int{b.X[:], b.Y[:]}, []*big.Int{c.X, c.Y}} packed, err := args.Pack(values...) if err != nil { return nil, fmt.Errorf("%v, values: %v", err, values) diff --git a/integration_tests/kzg_prover_test.go b/integration_tests/kzg_prover_test.go index 4491d548..8c4a5a92 100644 --- a/integration_tests/kzg_prover_test.go +++ b/integration_tests/kzg_prover_test.go @@ -112,7 +112,7 @@ func uploadBlob(t *testing.T, data []byte) common.Hash { {Type: uint256Type}, {Type: uint256Type}, } - values := []interface{}{blbKey, blbIdx, length} + values := []any{blbKey, blbIdx, length} dataField, err := args.Pack(values...) if err != nil { t.Fatalf("Error getting calldata: %v", err) @@ -175,7 +175,7 @@ func verifyInclusive(sampleIdx uint64, peInput []byte) error { {Type: uint256Type}, {Type: bytesType}, } - values := []interface{}{dataHash, index, decodedData, peInput} + values := []any{dataHash, index, decodedData, peInput} dataField, err := args.Pack(values...) if err != nil { return err diff --git a/integration_tests/zk_prover2_test.go b/integration_tests/zk_prover2_test.go index adbd365b..82d6bec1 100644 --- a/integration_tests/zk_prover2_test.go +++ b/integration_tests/zk_prover2_test.go @@ -62,13 +62,13 @@ func TestZKProver_GenerateZKProof(t *testing.T) { t.Errorf("ZKProver.GenerateInputs() error = %v", err) return } - var inputs map[string]interface{} + var inputs map[string]any err = json.Unmarshal(inputsBytes, &inputs) if err != nil { t.Errorf("ZKProver.GenerateInputs() error = %v", err) return } - vxIn, ok := inputs["xIn"].([]interface{}) + vxIn, ok := inputs["xIn"].([]any) if !ok { t.Errorf("ZKProver.GenerateInputs() type: %v, want []interface{}", reflect.TypeOf(inputs["xIn"])) return diff --git a/integration_tests/zk_prover_test.go b/integration_tests/zk_prover_test.go index 42c4fa54..fbbb0303 100644 --- a/integration_tests/zk_prover_test.go +++ b/integration_tests/zk_prover_test.go @@ -79,7 +79,7 @@ func TestZKProver_GenerateZKProofPerSample(t *testing.T) { t.Errorf("ZKProver.GenerateInput() error = %v", err) return } - var inputs map[string]interface{} + var inputs map[string]any err = json.Unmarshal(inputBytes, &inputs) if err != nil { t.Errorf("ZKProver.GenerateInput() error = %v", err)