Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterHandler ¶
RegisterHandler serves code-by-hash requests at p2p.EVMCodeRequestHandlerID on net.
Types ¶
type Client ¶
type Client = network.Dispatcher[*syncpb.GetCodeRequest, *syncpb.GetCodeResponse]
Client sends code-by-hash requests.
func NewClient ¶
func NewClient(n *p2p.Network, peers *p2p.PeerTracker) *Client
NewClient binds a Client at p2p.EVMCodeRequestHandlerID on n.
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer resolves contract code by hash from peers.
func NewSyncer ¶
NewSyncer returns a Syncer that downloads contract code through c and writes it to db. A restarted sync resumes where the previous one left off.
func (*Syncer) AddCode ¶
AddCode marks code hashes to be fetched during syncing. If AddCode returns nil, the code will be populated by the time Syncer.Sync returns nil, even if the node crashes and the syncer restarts.
AddCode NEVER blocks on the network, so it is safe to call from the VM's app message handlers. If it did, those handlers could deadlock with the syncer's own code requests.
func (*Syncer) DoneAdding ¶
func (s *Syncer) DoneAdding()
DoneAdding stops Syncer.AddCode from accepting new hashes and allows Syncer.Sync to return once it finishes fetching the queued hashes.
DoneAdding is idempotent and safe to call at any time.
func (*Syncer) Sync ¶
Sync runs until Syncer.DoneAdding has been called and every hash given to Syncer.AddCode has its code on disk, or until ctx is cancelled.
Sync MUST be called at most once. A cancelled Sync leaves hashes claimed but unfetched, and only the recovery in NewSyncer re-enqueues them, so each attempt needs a fresh Syncer.