-
Notifications
You must be signed in to change notification settings - Fork 275
sync: coreth PR #963,981,1009: sync package extension and related items #1679
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
01053b3
f3fd073
d04a7fc
239a3b5
52e4d26
34e3c48
ae531aa
38ecb7e
08bf133
a759870
912b506
892379e
c7c0c9a
4719758
434fb4f
936aacc
0edb94f
af00a05
3cb3808
728620c
52aba0c
eb25788
6ba1bd6
59a0ccc
07edff7
2564286
fa8a32d
5d911d5
14c8028
8fa7586
94c2b46
5b7d576
8426e2a
24e0ae0
7e55ada
ac0b665
2a46756
40abb33
ba927d5
0cc7e3b
cced3ca
291003a
e84bf4a
2356b60
9e4a453
509e349
33837af
55f46e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,7 @@ type Config struct { | |
MaxOutboundActiveRequests int64 `json:"max-outbound-active-requests"` | ||
|
||
// Sync settings | ||
StateSyncEnabled bool `json:"state-sync-enabled"` | ||
StateSyncEnabled *bool `json:"state-sync-enabled"` // Pointer distinguishes false (no state sync) and not set (state sync only at genesis). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why have we changed this? This is a substantial change for default value, we should have a separate PR for that if we want to align them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have changed this because this was a change that Darioush made years ago to See ava-labs/coreth@cd3a14e#diff-6c4b2fd34f767685bfc35038a59ea4fbfadaa6060d70031002e3b008e73a06e7. I have created a targeted PR for this change (and this change does need to be synced): |
||
StateSyncSkipResume bool `json:"state-sync-skip-resume"` // Forces state sync to use the highest available summary block | ||
StateSyncServerTrieCache int `json:"state-sync-server-trie-cache"` | ||
StateSyncIDs string `json:"state-sync-ids"` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package extension | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/ava-labs/avalanchego/database" | ||
"github.com/ava-labs/avalanchego/database/versiondb" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/network/p2p" | ||
"github.com/ava-labs/avalanchego/snow/consensus/snowman" | ||
avalanchecommon "github.com/ava-labs/avalanchego/snow/engine/common" | ||
"github.com/ava-labs/avalanchego/utils/timer/mockable" | ||
|
||
"github.com/ava-labs/avalanchego/snow/engine/snowman/block" | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/ava-labs/subnet-evm/consensus/dummy" | ||
"github.com/ava-labs/subnet-evm/core" | ||
"github.com/ava-labs/subnet-evm/params" | ||
"github.com/ava-labs/subnet-evm/params/extras" | ||
"github.com/ava-labs/subnet-evm/plugin/evm/config" | ||
"github.com/ava-labs/subnet-evm/plugin/evm/message" | ||
"github.com/ava-labs/subnet-evm/plugin/evm/sync" | ||
"github.com/ava-labs/subnet-evm/sync/handlers" | ||
|
||
"github.com/ava-labs/libevm/common" | ||
"github.com/ava-labs/libevm/core/types" | ||
) | ||
|
||
var ( | ||
errNilConfig = errors.New("nil extension config") | ||
errNilSyncSummaryProvider = errors.New("nil sync summary provider") | ||
errNilSyncableParser = errors.New("nil syncable parser") | ||
errNilClock = errors.New("nil clock") | ||
) | ||
|
||
type ExtensibleVM interface { | ||
// SetExtensionConfig sets the configuration for the VM extension | ||
// Should be called before any other method and only once | ||
SetExtensionConfig(config *Config) error | ||
// NewClient returns a client to send messages with for the given protocol | ||
NewClient(protocol uint64, options ...p2p.ClientOption) *p2p.Client | ||
// AddHandler registers a server handler for an application protocol | ||
AddHandler(protocol uint64, handler p2p.Handler) error | ||
// GetExtendedBlock returns the VMBlock for the given ID or an error if the block is not found | ||
GetExtendedBlock(context.Context, ids.ID) (ExtendedBlock, error) | ||
// LastAcceptedExtendedBlock returns the last accepted VM block | ||
LastAcceptedExtendedBlock() ExtendedBlock | ||
// ChainConfig returns the chain config for the VM | ||
ChainConfig() *params.ChainConfig | ||
// P2PValidators returns the validators for the network | ||
P2PValidators() *p2p.Validators | ||
// Blockchain returns the blockchain client | ||
Blockchain() *core.BlockChain | ||
// Config returns the configuration for the VM | ||
Config() config.Config | ||
// MetricRegistry returns the metric registry for the VM | ||
MetricRegistry() *prometheus.Registry | ||
// ReadLastAccepted returns the last accepted block hash and height | ||
ReadLastAccepted() (common.Hash, uint64, error) | ||
// VersionDB returns the versioned database for the VM | ||
VersionDB() *versiondb.Database | ||
} | ||
|
||
// InnerVM is the interface that must be implemented by the VM | ||
// that's being wrapped by the extension | ||
type InnerVM interface { | ||
ExtensibleVM | ||
avalanchecommon.VM | ||
block.ChainVM | ||
block.BuildBlockWithContextChainVM | ||
block.StateSyncableVM | ||
} | ||
|
||
// ExtendedBlock is a block that can be used by the extension | ||
type ExtendedBlock interface { | ||
snowman.Block | ||
GetEthBlock() *types.Block | ||
GetBlockExtension() BlockExtension | ||
} | ||
|
||
type BlockExtender interface { | ||
// NewBlockExtension is called when a new block is created | ||
NewBlockExtension(b ExtendedBlock) (BlockExtension, error) | ||
} | ||
|
||
// BlockExtension allows the VM extension to handle block processing events. | ||
type BlockExtension interface { | ||
// SyntacticVerify verifies the block syntactically | ||
// it can be implemented to extend inner block verification | ||
SyntacticVerify(rules extras.Rules) error | ||
// SemanticVerify verifies the block semantically | ||
// it can be implemented to extend inner block verification | ||
SemanticVerify() error | ||
// CleanupVerified is called when a block has passed SemanticVerify and SynctacticVerify, | ||
// and should be cleaned up due to error or verification runs under non-write mode. This | ||
// does not return an error because the block has already been verified. | ||
CleanupVerified() | ||
// Accept is called when a block is accepted by the block manager. Accept takes a | ||
// database.Batch that contains the changes that were made to the database as a result | ||
// of accepting the block. The changes in the batch should be flushed to the database in this method. | ||
Accept(acceptedBatch database.Batch) error | ||
// Reject is called when a block is rejected by the block manager | ||
Reject() error | ||
} | ||
|
||
// BuilderMempool is a mempool that's used in the block builder | ||
type BuilderMempool interface { | ||
// PendingLen returns the number of pending transactions | ||
// that are waiting to be included in a block | ||
PendingLen() int | ||
// SubscribePendingTxs returns a channel that's signaled when there are pending transactions | ||
SubscribePendingTxs() <-chan struct{} | ||
} | ||
|
||
// LeafRequestConfig is the configuration to handle leaf requests | ||
// in the network and syncer | ||
type LeafRequestConfig struct { | ||
// LeafType is the type of the leaf node | ||
LeafType message.NodeType | ||
// MetricName is the name of the metric to use for the leaf request | ||
MetricName string | ||
// Handler is the handler to use for the leaf request | ||
Handler handlers.LeafRequestHandler | ||
} | ||
|
||
// Config is the configuration for the VM extension | ||
type Config struct { | ||
// ConsensusCallbacks is the consensus callbacks to use | ||
// for the VM to be used in consensus engine. | ||
// Callback functions can be nil. | ||
ConsensusCallbacks dummy.ConsensusCallbacks | ||
// SyncSummaryProvider is the sync summary provider to use | ||
// for the VM to be used in syncer. | ||
// It's required and should be non-nil | ||
SyncSummaryProvider sync.SummaryProvider | ||
// SyncExtender can extend the syncer to handle custom sync logic. | ||
// It's optional and can be nil | ||
SyncExtender sync.Extender | ||
// SyncableParser is to parse summary messages from the network. | ||
// It's required and should be non-nil | ||
SyncableParser message.SyncableParser | ||
// BlockExtender allows the VM extension to create an extension to handle block processing events. | ||
// It's optional and can be nil | ||
BlockExtender BlockExtender | ||
// ExtraSyncLeafHandlerConfig is the extra configuration to handle leaf requests | ||
// in the network and syncer. It's optional and can be nil | ||
ExtraSyncLeafHandlerConfig *LeafRequestConfig | ||
// ExtraMempool is the mempool to be used in the block builder. | ||
// It's optional and can be nil | ||
ExtraMempool BuilderMempool | ||
// Clock is the clock to use for time related operations. | ||
// It's optional and can be nil | ||
Clock *mockable.Clock | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
if c == nil { | ||
return errNilConfig | ||
} | ||
if c.SyncSummaryProvider == nil { | ||
return errNilSyncSummaryProvider | ||
} | ||
if c.SyncableParser == nil { | ||
return errNilSyncableParser | ||
} | ||
if c.Clock == nil { | ||
return errNilClock | ||
} | ||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,37 @@ const MaxCodeHashesPerRequest = 5 | |
|
||
var _ Request = LeafsRequest{} | ||
|
||
// NodeType outlines the trie that a leaf node belongs to | ||
// handlers.LeafsRequestHandler uses this information to determine | ||
// which trie type to fetch the information from | ||
type NodeType uint8 | ||
|
||
const ( | ||
StateTrieNode = NodeType(1) | ||
StateTrieKeyLength = common.HashLength | ||
) | ||
|
||
// LeafsRequest is a request to receive trie leaves at specified Root within Start and End byte range | ||
// Limit outlines maximum number of leaves to returns starting at Start | ||
// NodeType outlines which trie to read from state/atomic. | ||
type LeafsRequest struct { | ||
Root common.Hash `serialize:"true"` | ||
Account common.Hash `serialize:"true"` | ||
Start []byte `serialize:"true"` | ||
End []byte `serialize:"true"` | ||
Limit uint16 `serialize:"true"` | ||
Root common.Hash `serialize:"true"` | ||
Account common.Hash `serialize:"true"` | ||
Start []byte `serialize:"true"` | ||
End []byte `serialize:"true"` | ||
Limit uint16 `serialize:"true"` | ||
NodeType NodeType `serialize:"true"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a breaking change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For serialization? It probably is, although this didn't seem to be noted in coreth - are there reprecussions you want to avoid here? Minimizing difference with coreth was the driving goal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
func (l LeafsRequest) String() string { | ||
return fmt.Sprintf( | ||
"LeafsRequest(Root=%s, Account=%s, Start=%s, End %s, Limit=%d)", | ||
l.Root, l.Account, common.Bytes2Hex(l.Start), common.Bytes2Hex(l.End), l.Limit, | ||
"LeafsRequest(Root=%s, Account=%s, Start=%s, End=%s, Limit=%d, NodeType=%d)", | ||
l.Root, l.Account, common.Bytes2Hex(l.Start), common.Bytes2Hex(l.End), l.Limit, l.NodeType, | ||
) | ||
} | ||
|
||
func (l LeafsRequest) Handle(ctx context.Context, nodeID ids.NodeID, requestID uint32, handler RequestHandler) ([]byte, error) { | ||
return handler.HandleStateTrieLeafsRequest(ctx, nodeID, requestID, l) | ||
return handler.HandleLeafsRequest(ctx, nodeID, requestID, l) | ||
} | ||
|
||
// LeafsResponse is a response to a LeafsRequest | ||
|
Uh oh!
There was an error while loading. Please reload this page.