github.com/MetalBlockchain/subnet-evm@v0.4.9/plugin/evm/message/leafs_request.go (about)

     1  // (c) 2021-2022, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package message
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  
    10  	"github.com/MetalBlockchain/metalgo/ids"
    11  	"github.com/ethereum/go-ethereum/common"
    12  )
    13  
    14  const MaxCodeHashesPerRequest = 5
    15  
    16  var _ Request = LeafsRequest{}
    17  
    18  // LeafsRequest is a request to receive trie leaves at specified Root within Start and End byte range
    19  // Limit outlines maximum number of leaves to returns starting at Start
    20  type LeafsRequest struct {
    21  	Root    common.Hash `serialize:"true"`
    22  	Account common.Hash `serialize:"true"`
    23  	Start   []byte      `serialize:"true"`
    24  	End     []byte      `serialize:"true"`
    25  	Limit   uint16      `serialize:"true"`
    26  }
    27  
    28  func (l LeafsRequest) String() string {
    29  	return fmt.Sprintf(
    30  		"LeafsRequest(Root=%s, Account=%s, Start=%s, End %s, Limit=%d)",
    31  		l.Root, l.Account, common.Bytes2Hex(l.Start), common.Bytes2Hex(l.End), l.Limit,
    32  	)
    33  }
    34  
    35  func (l LeafsRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) {
    36  	return handler.HandleTrieLeafsRequest(ctx, nodeID, requestID, l)
    37  }
    38  
    39  // LeafsResponse is a response to a LeafsRequest
    40  // Keys must be within LeafsRequest.Start and LeafsRequest.End and sorted in lexicographical order.
    41  //
    42  // ProofKeys and ProofVals are expected to be non-nil and valid range proofs if the key-value pairs
    43  // in the response are not the entire trie.
    44  // If the key-value pairs make up the entire trie, ProofKeys and ProofVals should be empty since the
    45  // root will be sufficient to prove that the leaves are included in the trie.
    46  //
    47  // More is a flag set in the client after verifying the response, which indicates if the last key-value
    48  // pair in the response has any more elements to its right within the trie.
    49  type LeafsResponse struct {
    50  	// Keys and Vals provides the key-value pairs in the trie in the response.
    51  	Keys [][]byte `serialize:"true"`
    52  	Vals [][]byte `serialize:"true"`
    53  
    54  	// More indicates if there are more leaves to the right of the last value in this response.
    55  	//
    56  	// This is not serialized since it is set in the client after verifying the response via
    57  	// VerifyRangeProof and determining if there are in fact more leaves to the right of the
    58  	// last value in this response.
    59  	More bool
    60  
    61  	// ProofVals contain the edge merkle-proofs for the range of keys included in the response.
    62  	// The keys for the proof are simply the keccak256 hashes of the values, so they are not included in the response to save bandwidth.
    63  	ProofVals [][]byte `serialize:"true"`
    64  }