Files
coreth/sync/atomic/summary.go
zeekay dd02f9cc9b chore: remove local replace directive and update vm dependency
- Update github.com/luxfi/vm v1.0.1 → v1.0.2
- Remove local replace directive for vm
- Use published package versions for reproducible builds
2026-01-03 07:11:08 -08:00

75 lines
1.9 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package atomic
import (
"context"
"fmt"
"github.com/luxfi/coreth/plugin/evm/message"
"github.com/luxfi/ids"
"github.com/luxfi/consensus/engine/chain/block"
"github.com/luxfi/crypto"
"github.com/luxfi/geth/common"
)
var _ message.Syncable = (*Summary)(nil)
// Summary provides the information necessary to sync a node starting
// at the given block.
type Summary struct {
*message.BlockSyncSummary `serialize:"true"`
AtomicRoot common.Hash `serialize:"true"`
summaryID ids.ID
bytes []byte
acceptImpl message.AcceptImplFn
}
func NewSummary(blockHash common.Hash, blockNumber uint64, blockRoot common.Hash, atomicRoot common.Hash) (*Summary, error) {
// We intentionally do not use the acceptImpl here and leave it for the parser to set.
summary := Summary{
BlockSyncSummary: &message.BlockSyncSummary{
BlockNumber: blockNumber,
BlockHash: blockHash,
BlockRoot: blockRoot,
},
AtomicRoot: atomicRoot,
}
bytes, err := message.Codec.Marshal(message.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 (a *Summary) Bytes() []byte {
return a.bytes
}
func (a *Summary) ID() ids.ID {
return a.summaryID
}
func (a *Summary) String() string {
return fmt.Sprintf("Summary(BlockHash=%s, BlockNumber=%d, BlockRoot=%s, AtomicRoot=%s)", a.BlockHash, a.BlockNumber, a.BlockRoot, a.AtomicRoot)
}
func (a *Summary) Accept(context.Context) (block.StateSyncMode, error) {
if a.acceptImpl == nil {
return block.StateSyncSkipped, fmt.Errorf("accept implementation not specified for summary: %s", a)
}
return a.acceptImpl(a)
}