- 
                Notifications
    You must be signed in to change notification settings 
- Fork 816
          chore(sync/message): migrate message package for EVM state sync from coreth
          #4417
        
          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
          
     Open
      
      
            powerslider
  wants to merge
  8
  commits into
  master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
powerslider/4416-migrate-message-coreth
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      4c56250
              
                chore(sync/message): migrate message package for EVM state sync from …
              
              
                powerslider b93d0dc
              
                test: simplify request_test
              
              
                powerslider 2bf6393
              
                test: simplify request_test
              
              
                powerslider 479821c
              
                test: separate block sync summary parse tests into a new file
              
              
                powerslider c1bdcdb
              
                Merge branch 'master' into powerslider/4416-migrate-message-coreth
              
              
                powerslider ede1a7e
              
                style: consistency fixes
              
              
                powerslider cd88b59
              
                Merge branch 'master' into powerslider/4416-migrate-message-coreth
              
              
                powerslider 0f51554
              
                Merge branch 'master' into powerslider/4416-migrate-message-coreth
              
              
                powerslider File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "context" | ||
| "fmt" | ||
|  | ||
| "github.com/ava-labs/libevm/common" | ||
|  | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| ) | ||
|  | ||
| var _ Request = (*BlockRequest)(nil) | ||
|  | ||
| // BlockRequest is a request to retrieve Parents number of blocks starting from Hash from newest-oldest manner | ||
| type BlockRequest struct { | ||
| Hash common.Hash `serialize:"true"` | ||
| Height uint64 `serialize:"true"` | ||
| Parents uint16 `serialize:"true"` | ||
| } | ||
|  | ||
| func (b BlockRequest) String() string { | ||
| return fmt.Sprintf( | ||
| "BlockRequest(Hash=%s, Height=%d, Parents=%d)", | ||
| b.Hash, b.Height, b.Parents, | ||
| ) | ||
| } | ||
|  | ||
| func (b BlockRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) { | ||
| return handler.HandleBlockRequest(ctx, nodeID, requestID, b) | ||
| } | ||
|  | ||
| // BlockResponse is a response to a BlockRequest | ||
| // Blocks is slice of RLP encoded blocks starting with the block | ||
| // requested in BlockRequest.Hash. The next block is the parent, etc. | ||
| // handler: handlers.BlockRequestHandler | ||
| type BlockResponse struct { | ||
| Blocks [][]byte `serialize:"true"` | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "encoding/base64" | ||
| "math/rand" | ||
| "testing" | ||
|  | ||
| "github.com/ava-labs/libevm/common" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|  | ||
| // TestMarshalBlockRequest requires that the structure or serialization logic hasn't changed, primarily to | ||
| // ensure compatibility with the network. | ||
| func TestMarshalBlockRequest(t *testing.T) { | ||
| blockRequest := BlockRequest{ | ||
| Hash: common.BytesToHash([]byte("some hash is here yo")), | ||
| Height: 1337, | ||
| Parents: 64, | ||
| } | ||
|  | ||
| base64BlockRequest := "AAAAAAAAAAAAAAAAAABzb21lIGhhc2ggaXMgaGVyZSB5bwAAAAAAAAU5AEA=" | ||
|  | ||
| blockRequestBytes, err := Codec.Marshal(Version, blockRequest) | ||
| require.NoError(t, err) | ||
| require.Equal(t, base64BlockRequest, base64.StdEncoding.EncodeToString(blockRequestBytes)) | ||
|  | ||
| var b BlockRequest | ||
| _, err = Codec.Unmarshal(blockRequestBytes, &b) | ||
| require.NoError(t, err) | ||
| require.Equal(t, blockRequest.Hash, b.Hash) | ||
| require.Equal(t, blockRequest.Height, b.Height) | ||
| require.Equal(t, blockRequest.Parents, b.Parents) | ||
| } | ||
|  | ||
| // TestMarshalBlockResponse requires that the structure or serialization logic hasn't changed, primarily to | ||
| // ensure compatibility with the network. | ||
| func TestMarshalBlockResponse(t *testing.T) { | ||
| // create some random bytes | ||
| // set seed to ensure deterministic random behaviour | ||
| r := rand.New(rand.NewSource(1)) //nolint:gosec // deterministic bytes for golden assertion | ||
| blocksBytes := make([][]byte, 32) | ||
| for i := range blocksBytes { | ||
| blocksBytes[i] = make([]byte, r.Intn(32)+32) | ||
| _, err := r.Read(blocksBytes[i]) | ||
| require.NoError(t, err) | ||
| } | ||
|  | ||
| blockResponse := BlockResponse{ | ||
| Blocks: blocksBytes, | ||
| } | ||
|  | ||
| base64BlockResponse := "AAAAAAAgAAAAIU8WP18PmmIdcpVmx00QA3xNe7sEB9HixkmBhVrYaB0NhgAAADnR6ZTSxCKs0gigByk5SH9pm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FbQgAqGkTMgiKgFvVXERuJesHU=" | ||
|  | ||
| blockResponseBytes, err := Codec.Marshal(Version, blockResponse) | ||
| require.NoError(t, err) | ||
| require.Equal(t, base64BlockResponse, base64.StdEncoding.EncodeToString(blockResponseBytes)) | ||
|  | ||
| var b BlockResponse | ||
| _, err = Codec.Unmarshal(blockResponseBytes, &b) | ||
| require.NoError(t, err) | ||
| require.Equal(t, blockResponse.Blocks, b.Blocks) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "context" | ||
| "fmt" | ||
|  | ||
| "github.com/ava-labs/libevm/common" | ||
| "github.com/ava-labs/libevm/crypto" | ||
|  | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| "github.com/ava-labs/avalanchego/snow/engine/snowman/block" | ||
| ) | ||
|  | ||
| var _ Syncable = (*BlockSyncSummary)(nil) | ||
|  | ||
| // BlockSyncSummary provides the information necessary to sync a node starting | ||
| // at the given block. | ||
| type BlockSyncSummary struct { | ||
| BlockNumber uint64 `serialize:"true"` | ||
| BlockHash common.Hash `serialize:"true"` | ||
| BlockRoot common.Hash `serialize:"true"` | ||
|  | ||
| summaryID ids.ID | ||
| bytes []byte | ||
| acceptImpl AcceptImplFn | ||
| } | ||
|  | ||
| func NewBlockSyncSummary(blockHash common.Hash, blockNumber uint64, blockRoot common.Hash) (*BlockSyncSummary, error) { | ||
| // We intentionally do not use the acceptImpl here and leave it for the parser to set. | ||
| summary := BlockSyncSummary{ | ||
| BlockNumber: blockNumber, | ||
| BlockHash: blockHash, | ||
| BlockRoot: blockRoot, | ||
| } | ||
| bytes, err := Codec.Marshal(Version, &summary) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to marshal syncable summary: %w", err) | ||
| } | ||
|  | ||
| summary.bytes = bytes | ||
| summaryID, err := ids.ToID(crypto.Keccak256(bytes)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to compute summary ID: %w", err) | ||
| } | ||
| summary.summaryID = summaryID | ||
|  | ||
| return &summary, nil | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) GetBlockHash() common.Hash { | ||
| return s.BlockHash | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) GetBlockRoot() common.Hash { | ||
| return s.BlockRoot | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) Bytes() []byte { | ||
| return s.bytes | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) Height() uint64 { | ||
| return s.BlockNumber | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) ID() ids.ID { | ||
| return s.summaryID | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) String() string { | ||
| return fmt.Sprintf("BlockSyncSummary(BlockHash=%s, BlockNumber=%d, BlockRoot=%s)", s.BlockHash, s.BlockNumber, s.BlockRoot) | ||
| } | ||
|  | ||
| func (s *BlockSyncSummary) Accept(context.Context) (block.StateSyncMode, error) { | ||
| if s.acceptImpl == nil { | ||
| return block.StateSyncSkipped, fmt.Errorf("accept implementation not specified for summary: %s", s) | ||
| } | ||
| return s.acceptImpl(s) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|  | ||
| "github.com/ava-labs/libevm/crypto" | ||
|  | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| ) | ||
|  | ||
| // errInvalidBlockSyncSummary is returned when the provided bytes cannot be | ||
| // parsed into a valid BlockSyncSummary. | ||
| var errInvalidBlockSyncSummary = errors.New("invalid block sync summary") | ||
|  | ||
| type BlockSyncSummaryParser struct{} | ||
|  | ||
| func NewBlockSyncSummaryParser() *BlockSyncSummaryParser { | ||
| return &BlockSyncSummaryParser{} | ||
| } | ||
|  | ||
| func (*BlockSyncSummaryParser) Parse(summaryBytes []byte, acceptImpl AcceptImplFn) (Syncable, error) { | ||
| summary := BlockSyncSummary{} | ||
| if _, err := Codec.Unmarshal(summaryBytes, &summary); err != nil { | ||
| return nil, fmt.Errorf("%w", errInvalidBlockSyncSummary) | ||
| } | ||
|  | ||
| summary.bytes = summaryBytes | ||
| summaryID, err := ids.ToID(crypto.Keccak256(summaryBytes)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to compute summary ID: %w", err) | ||
| } | ||
| summary.summaryID = summaryID | ||
| summary.acceptImpl = acceptImpl | ||
| return &summary, nil | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "context" | ||
| "testing" | ||
|  | ||
| "github.com/ava-labs/libevm/common" | ||
| "github.com/stretchr/testify/require" | ||
|  | ||
| "github.com/ava-labs/avalanchego/snow/engine/snowman/block" | ||
| ) | ||
|  | ||
| func TestBlockSyncSummaryParser_ParseValid(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| blockSyncSummary, err := NewBlockSyncSummary(common.Hash{1}, 2, common.Hash{3}) | ||
| require.NoError(t, err) | ||
|  | ||
| parser := NewBlockSyncSummaryParser() | ||
| called := false | ||
| acceptImplTest := func(Syncable) (block.StateSyncMode, error) { | ||
| called = true | ||
| return block.StateSyncSkipped, nil | ||
| } | ||
| s, err := parser.Parse(blockSyncSummary.Bytes(), acceptImplTest) | ||
| require.NoError(t, err) | ||
| require.Equal(t, blockSyncSummary.GetBlockHash(), s.GetBlockHash()) | ||
| require.Equal(t, blockSyncSummary.Height(), s.Height()) | ||
| require.Equal(t, blockSyncSummary.GetBlockRoot(), s.GetBlockRoot()) | ||
| require.Equal(t, blockSyncSummary.Bytes(), s.Bytes()) | ||
|  | ||
| mode, err := s.Accept(context.Background()) | ||
| require.NoError(t, err) | ||
| require.Equal(t, block.StateSyncSkipped, mode) | ||
| require.True(t, called) | ||
| } | ||
|  | ||
| func TestBlockSyncSummaryParser_ParseInvalid(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| parser := NewBlockSyncSummaryParser() | ||
| _, err := parser.Parse([]byte("not-a-summary"), nil) | ||
| require.ErrorIs(t, err, errInvalidBlockSyncSummary) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "github.com/ava-labs/libevm/core/types" | ||
|  | ||
| "github.com/ava-labs/avalanchego/snow/engine/snowman/block" | ||
| ) | ||
|  | ||
| type BlockSyncSummaryProvider struct{} | ||
|  | ||
| // StateSummaryAtBlock returns the block state summary at [block] if valid. | ||
| func (*BlockSyncSummaryProvider) StateSummaryAtBlock(blk *types.Block) (block.StateSummary, error) { | ||
| return NewBlockSyncSummary(blk.Hash(), blk.NumberU64(), blk.Root()) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "encoding/base64" | ||
| "testing" | ||
|  | ||
| "github.com/ava-labs/libevm/common" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|  | ||
| func TestBlockSyncSummary_MarshalGolden(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| blockSyncSummary, err := NewBlockSyncSummary(common.Hash{1}, 2, common.Hash{3}) | ||
| require.NoError(t, err) | ||
|  | ||
| require.Equal(t, common.Hash{1}, blockSyncSummary.GetBlockHash()) | ||
| require.Equal(t, uint64(2), blockSyncSummary.Height()) | ||
| require.Equal(t, common.Hash{3}, blockSyncSummary.GetBlockRoot()) | ||
|  | ||
| expectedBase64Bytes := "AAAAAAAAAAAAAgEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" | ||
| require.Equal(t, expectedBase64Bytes, base64.StdEncoding.EncodeToString(blockSyncSummary.Bytes())) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| // Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
| // See the file LICENSE for licensing terms. | ||
|  | ||
| package message | ||
|  | ||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "strings" | ||
|  | ||
| "github.com/ava-labs/libevm/common" | ||
|  | ||
| "github.com/ava-labs/avalanchego/ids" | ||
| ) | ||
|  | ||
| var _ Request = (*CodeRequest)(nil) | ||
|  | ||
| // CodeRequest is a request to retrieve a contract code with specified Hash | ||
| type CodeRequest struct { | ||
| // Hashes is a list of contract code hashes | ||
| Hashes []common.Hash `serialize:"true"` | ||
| } | ||
|  | ||
| func (c CodeRequest) String() string { | ||
| hashStrs := make([]string, len(c.Hashes)) | ||
| for i, hash := range c.Hashes { | ||
| hashStrs[i] = hash.String() | ||
| } | ||
| return fmt.Sprintf("CodeRequest(Hashes=%s)", strings.Join(hashStrs, ", ")) | ||
| } | ||
|  | ||
| func (c CodeRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) { | ||
| return handler.HandleCodeRequest(ctx, nodeID, requestID, c) | ||
| } | ||
|  | ||
| func NewCodeRequest(hashes []common.Hash) CodeRequest { | ||
| return CodeRequest{ | ||
| Hashes: hashes, | ||
| } | ||
| } | ||
|  | ||
| // CodeResponse is a response to a CodeRequest | ||
| // crypto.Keccak256Hash of each element in Data is expected to equal | ||
| // the corresponding element in CodeRequest.Hashes | ||
| // handler: handlers.CodeRequestHandler | ||
| type CodeResponse struct { | ||
| Data [][]byte `serialize:"true"` | ||
| } | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is referring to the handlers package in coreth right? are we looking to move this over as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sorry I missed this reference in the comment, but the handlers will be migrated as well in a follow up PR.