-
Notifications
You must be signed in to change notification settings - Fork 142
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
move node types and handlings to separate packages #729
base: move-atomic-sync
Are you sure you want to change the base?
Changes from all commits
7526804
a18f8a4
a2b8a58
2314929
861b60f
0434acc
c2ae919
e7b47f2
fb7c678
472a8d3
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ package evm | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ava-labs/avalanchego/codec" | ||
"github.com/ava-labs/avalanchego/ids" | ||
|
@@ -21,38 +22,52 @@ import ( | |
var _ message.RequestHandler = &networkHandler{} | ||
|
||
type networkHandler struct { | ||
stateTrieLeafsRequestHandler *syncHandlers.LeafsRequestHandler | ||
atomicTrieLeafsRequestHandler *syncHandlers.LeafsRequestHandler | ||
blockRequestHandler *syncHandlers.BlockRequestHandler | ||
codeRequestHandler *syncHandlers.CodeRequestHandler | ||
signatureRequestHandler *warpHandlers.SignatureRequestHandler | ||
leafRequestHandlers map[message.NodeType]*syncHandlers.LeafsRequestHandler | ||
blockRequestHandler *syncHandlers.BlockRequestHandler | ||
codeRequestHandler *syncHandlers.CodeRequestHandler | ||
signatureRequestHandler *warpHandlers.SignatureRequestHandler | ||
} | ||
|
||
type LeafRequestTypeConfig struct { | ||
NodeType message.NodeType | ||
NodeKeyLen int | ||
TrieDB *triedb.Database | ||
UseSnapshots bool | ||
MetricName string | ||
} | ||
|
||
// newNetworkHandler constructs the handler for serving network requests. | ||
func newNetworkHandler( | ||
provider syncHandlers.SyncDataProvider, | ||
diskDB ethdb.KeyValueReader, | ||
evmTrieDB *triedb.Database, | ||
atomicTrieDB *triedb.Database, | ||
warpBackend warp.Backend, | ||
networkCodec codec.Manager, | ||
leafRequesTypeConfigs map[message.NodeType]LeafRequestTypeConfig, | ||
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. should we just take |
||
) message.RequestHandler { | ||
syncStats := syncStats.NewHandlerStats(metrics.Enabled) | ||
leafRequestHandlers := make(map[message.NodeType]*syncHandlers.LeafsRequestHandler) | ||
for _, config := range leafRequesTypeConfigs { | ||
snapshotProvider := provider | ||
if !config.UseSnapshots { | ||
snapshotProvider = nil | ||
} | ||
leafRequestHandler := syncHandlers.NewLeafsRequestHandler(config.TrieDB, config.NodeKeyLen, snapshotProvider, networkCodec, syncStats) | ||
leafRequestHandlers[config.NodeType] = leafRequestHandler | ||
} | ||
return &networkHandler{ | ||
stateTrieLeafsRequestHandler: syncHandlers.NewLeafsRequestHandler(evmTrieDB, provider, networkCodec, syncStats), | ||
atomicTrieLeafsRequestHandler: syncHandlers.NewLeafsRequestHandler(atomicTrieDB, nil, networkCodec, syncStats), | ||
blockRequestHandler: syncHandlers.NewBlockRequestHandler(provider, networkCodec, syncStats), | ||
codeRequestHandler: syncHandlers.NewCodeRequestHandler(diskDB, networkCodec, syncStats), | ||
signatureRequestHandler: warpHandlers.NewSignatureRequestHandler(warpBackend, networkCodec), | ||
leafRequestHandlers: leafRequestHandlers, | ||
blockRequestHandler: syncHandlers.NewBlockRequestHandler(provider, networkCodec, syncStats), | ||
codeRequestHandler: syncHandlers.NewCodeRequestHandler(diskDB, networkCodec, syncStats), | ||
signatureRequestHandler: warpHandlers.NewSignatureRequestHandler(warpBackend, networkCodec), | ||
} | ||
} | ||
|
||
func (n networkHandler) HandleStateTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest message.LeafsRequest) ([]byte, error) { | ||
return n.stateTrieLeafsRequestHandler.OnLeafsRequest(ctx, nodeID, requestID, leafsRequest) | ||
} | ||
|
||
func (n networkHandler) HandleAtomicTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest message.LeafsRequest) ([]byte, error) { | ||
return n.atomicTrieLeafsRequestHandler.OnLeafsRequest(ctx, nodeID, requestID, leafsRequest) | ||
func (n networkHandler) HandleLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest message.LeafsRequest) ([]byte, error) { | ||
handler, ok := n.leafRequestHandlers[leafsRequest.NodeType] | ||
if !ok { | ||
return nil, fmt.Errorf("unknown node type %d", leafsRequest.NodeType) | ||
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. I think this error will be fatal so we should log debug and return nil as before |
||
} | ||
return handler.OnLeafsRequest(ctx, nodeID, requestID, leafsRequest) | ||
} | ||
|
||
func (n networkHandler) HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, blockRequest message.BlockRequest) ([]byte, error) { | ||
|
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.
should we keep this as
1
for compatibility?