Skip to content

Commit a686022

Browse files
authored
Merge branch 'powerslider/4416-migrate-message-coreth' into powerslider/4368-migrate-stats-coreth
2 parents f3bf7c6 + 3df7e47 commit a686022

20 files changed

+539
-251
lines changed

api/info/service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ type PeersReply struct {
254254
Peers []Peer `json:"peers"`
255255
}
256256

257-
// Peers returns the list of current validators
257+
// Peers returns the current peers this node is connected to. If nodeIDs are
258+
// provided, the response is filtered to just include peers that match those
259+
// IDs.
258260
func (i *Info) Peers(_ *http.Request, args *PeersArgs, reply *PeersReply) error {
259261
i.log.Debug("API called",
260262
zap.String("service", "info"),

vms/evm/sync/message/block_request.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import (
1414

1515
var _ Request = (*BlockRequest)(nil)
1616

17-
// BlockRequest is a request to retrieve Parents number of blocks starting from Hash from newest-oldest manner
17+
// BlockRequest is a request to retrieve the specified number of parent blocks
18+
// starting from the given hash, ordered from newest to oldest.
1819
type BlockRequest struct {
1920
Hash common.Hash `serialize:"true"`
2021
Height uint64 `serialize:"true"`
@@ -32,10 +33,9 @@ func (b BlockRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID u
3233
return handler.HandleBlockRequest(ctx, nodeID, requestID, b)
3334
}
3435

35-
// BlockResponse is a response to a BlockRequest
36-
// Blocks is slice of RLP encoded blocks starting with the block
36+
// BlockResponse is a response to a BlockRequest.
37+
// Blocks is a slice of RLP-encoded blocks starting with the block
3738
// requested in BlockRequest.Hash. The next block is the parent, etc.
38-
// handler: handlers.BlockRequestHandler
3939
type BlockResponse struct {
4040
Blocks [][]byte `serialize:"true"`
4141
}

vms/evm/sync/message/block_request_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ func TestMarshalBlockRequest(t *testing.T) {
2323

2424
base64BlockRequest := "AAAAAAAAAAAAAAAAAABzb21lIGhhc2ggaXMgaGVyZSB5bwAAAAAAAAU5AEA="
2525

26-
blockRequestBytes, err := Codec.Marshal(Version, blockRequest)
26+
blockRequestBytes, err := Codec().Marshal(Version, blockRequest)
2727
require.NoError(t, err)
2828
require.Equal(t, base64BlockRequest, base64.StdEncoding.EncodeToString(blockRequestBytes))
2929

3030
var b BlockRequest
31-
_, err = Codec.Unmarshal(blockRequestBytes, &b)
31+
_, err = Codec().Unmarshal(blockRequestBytes, &b)
3232
require.NoError(t, err)
3333
require.Equal(t, blockRequest.Hash, b.Hash)
3434
require.Equal(t, blockRequest.Height, b.Height)
@@ -54,12 +54,12 @@ func TestMarshalBlockResponse(t *testing.T) {
5454

5555
base64BlockResponse := "AAAAAAAgAAAAIU8WP18PmmIdcpVmx00QA3xNe7sEB9HixkmBhVrYaB0NhgAAADnR6ZTSxCKs0gigByk5SH9pmeudGKRHhARdh/PGfPInRumVr1olNnlRuqL/bNRxxIPxX7kLrbN8WCEAAAA6tmgLTnyLdjobHUnUlVyEhiFjJSU/7HON16nii/khEZwWDwcCRIYVu9oIMT9qjrZo0gv1BZh1kh5migAAACtb3yx/xIRo0tbFL1BU4tCDa/hMcXTLdHY2TMPb2Wiw9xcu2FeUuzWLDDtSAAAAO12heG+f69ehnQ97usvgJVqlt9RL7ED4TIkrm//UNimwIjvupfT3Q5H0RdFa/UKUBAN09pJLmMv4cT+NAAAAMpYtJOLK/Mrjph+1hrFDI6a8j5598dkpMz/5k5M76m9bOvbeA3Q2bEcZ5DobBn2JvH8BAAAAOfHxekxyFaO1OeseWEnGB327VyL1cXoomiZvl2R5gZmOvqicC0s3OXARXoLtb0ElyPpzEeTX3vqSLQAAACc2zU8kq/ffhmuqVgODZ61hRd4e6PSosJk+vfiIOgrYvpw5eLBIg+UAAAAkahVqnexqQOmh0AfwM8KCMGG90Oqln45NpkMBBSINCyloi3NLAAAAKI6gENd8luqAp6Zl9gb2pjt/Pf0lZ8GJeeTWDyZobZvy+ybJAf81TN4AAAA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Wm7ZLaSCyqlWjltv6dip3QAAAC7Z6wkne1AJRMvoAKCxUn6mRymoYdL2SXoyNcN/QZJ3nsHZazscVCT84LcnsDByAAAAI+ZAq8lEj93rIZHZRcBHZ6+Eev0O212IV7eZrLGOSv+r4wN/AAAAL/7MQW5zTTc8Xr68nNzFlbzOPHvT2N+T+rfhJd3rr+ZaMb1dQeLSzpwrF4kvD+oZAAAAMTGikNy/poQG6HcHP/CINOGXpANKpIr6P4W4picIyuu6yIC1uJuT2lOBAWRAIQTmSLYAAAA1ImobDzE6id38RUxfj3KsibOLGfU3hMGem+rAPIdaJ9sCneN643pCMYgTSHaFkpNZyoxeuU4AAAA9FS3Br0LquOKSXG2u5N5e+fnc8I38vQK4CAk5hYWSig995QvhptwdV2joU3mI/dzlYum5SMkYu6PpM+XEAAAAAC3Nrne6HSWbGIpLIchvvCPXKLRTR+raZQryTFbQgAqGkTMgiKgFvVXERuJesHU="
5656

57-
blockResponseBytes, err := Codec.Marshal(Version, blockResponse)
57+
blockResponseBytes, err := Codec().Marshal(Version, blockResponse)
5858
require.NoError(t, err)
5959
require.Equal(t, base64BlockResponse, base64.StdEncoding.EncodeToString(blockResponseBytes))
6060

6161
var b BlockResponse
62-
_, err = Codec.Unmarshal(blockResponseBytes, &b)
62+
_, err = Codec().Unmarshal(blockResponseBytes, &b)
6363
require.NoError(t, err)
6464
require.Equal(t, blockResponse.Blocks, b.Blocks)
6565
}

vms/evm/sync/message/block_sync_summary.go

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,44 @@ package message
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910

1011
"github.com/ava-labs/libevm/common"
12+
"github.com/ava-labs/libevm/core/types"
1113
"github.com/ava-labs/libevm/crypto"
1214

1315
"github.com/ava-labs/avalanchego/ids"
1416
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
1517
)
1618

17-
var _ Syncable = (*BlockSyncSummary)(nil)
19+
var (
20+
_ Syncable = (*BlockSyncSummary)(nil)
21+
_ SyncableParser = (*BlockSyncSummaryParser)(nil)
22+
23+
// errInvalidBlockSyncSummary is returned when the provided bytes cannot be
24+
// parsed into a valid BlockSyncSummary.
25+
errInvalidBlockSyncSummary = errors.New("invalid block sync summary")
26+
27+
// errAcceptImplNotSpecified is returned when Accept is called on a BlockSyncSummary
28+
// that doesn't have an acceptImpl set.
29+
errAcceptImplNotSpecified = errors.New("accept implementation not specified")
30+
)
31+
32+
// Syncable extends [block.StateSummary] with EVM-specific block information.
33+
type Syncable interface {
34+
block.StateSummary
35+
GetBlockHash() common.Hash
36+
GetBlockRoot() common.Hash
37+
}
38+
39+
// SyncableParser parses raw bytes into a [Syncable] instance.
40+
type SyncableParser interface {
41+
Parse(summaryBytes []byte, acceptImpl AcceptImplFn) (Syncable, error)
42+
}
43+
44+
// AcceptImplFn is a function that determines the state sync mode for a given [Syncable].
45+
type AcceptImplFn func(Syncable) (block.StateSyncMode, error)
1846

1947
// BlockSyncSummary provides the information necessary to sync a node starting
2048
// at the given block.
@@ -28,14 +56,15 @@ type BlockSyncSummary struct {
2856
acceptImpl AcceptImplFn
2957
}
3058

59+
// NewBlockSyncSummary creates a new [BlockSyncSummary] for the given block.
60+
// The acceptImpl is intentionally left unset and should be set by the parser.
3161
func NewBlockSyncSummary(blockHash common.Hash, blockNumber uint64, blockRoot common.Hash) (*BlockSyncSummary, error) {
32-
// We intentionally do not use the acceptImpl here and leave it for the parser to set.
3362
summary := BlockSyncSummary{
3463
BlockNumber: blockNumber,
3564
BlockHash: blockHash,
3665
BlockRoot: blockRoot,
3766
}
38-
bytes, err := Codec.Marshal(Version, &summary)
67+
bytes, err := Codec().Marshal(Version, &summary)
3968
if err != nil {
4069
return nil, fmt.Errorf("failed to marshal syncable summary: %w", err)
4170
}
@@ -76,7 +105,39 @@ func (s *BlockSyncSummary) String() string {
76105

77106
func (s *BlockSyncSummary) Accept(context.Context) (block.StateSyncMode, error) {
78107
if s.acceptImpl == nil {
79-
return block.StateSyncSkipped, fmt.Errorf("accept implementation not specified for summary: %s", s)
108+
return block.StateSyncSkipped, errAcceptImplNotSpecified
80109
}
81110
return s.acceptImpl(s)
82111
}
112+
113+
// BlockSyncSummaryParser parses [BlockSyncSummary] instances from raw bytes.
114+
type BlockSyncSummaryParser struct{}
115+
116+
// NewBlockSyncSummaryParser creates a new [BlockSyncSummaryParser].
117+
func NewBlockSyncSummaryParser() *BlockSyncSummaryParser {
118+
return &BlockSyncSummaryParser{}
119+
}
120+
121+
func (*BlockSyncSummaryParser) Parse(summaryBytes []byte, acceptImpl AcceptImplFn) (Syncable, error) {
122+
summary := BlockSyncSummary{}
123+
if _, err := Codec().Unmarshal(summaryBytes, &summary); err != nil {
124+
return nil, fmt.Errorf("%w: %w", errInvalidBlockSyncSummary, err)
125+
}
126+
127+
summary.bytes = summaryBytes
128+
summaryID, err := ids.ToID(crypto.Keccak256(summaryBytes))
129+
if err != nil {
130+
return nil, fmt.Errorf("failed to compute summary ID: %w", err)
131+
}
132+
summary.summaryID = summaryID
133+
summary.acceptImpl = acceptImpl
134+
return &summary, nil
135+
}
136+
137+
// BlockSyncSummaryProvider provides state summaries for blocks.
138+
type BlockSyncSummaryProvider struct{}
139+
140+
// StateSummaryAtBlock returns the block state summary for the given block if valid.
141+
func (*BlockSyncSummaryProvider) StateSummaryAtBlock(blk *types.Block) (block.StateSummary, error) {
142+
return NewBlockSyncSummary(blk.Hash(), blk.NumberU64(), blk.Root())
143+
}

vms/evm/sync/message/block_sync_summary_parser.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

vms/evm/sync/message/block_sync_summary_parser_test.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

vms/evm/sync/message/block_sync_summary_provider.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)