mirror of
https://github.com/luxfi/coreth.git
synced 2026-10-30 17:00:51 +00:00
Drop github.com/luxfi/codec from the atomic-tx subsystem and replace the reflection-based polymorphic registry with a hand-rolled binary encoder. Type IDs preserved from the legacy linearcodec registration order (UnsignedImportTx=0, UnsignedExportTx=1, TransferInput=5, TransferOutput=7, secp256k1fx.Credential=9) so on-disk blobs and p2p gossip framing stay byte-equal to legacy. New atomic.Manager interface mirrors the message.Manager pattern shipped in Wave 1C — Marshal/Unmarshal only, no reflection registry. The atomic.Codec singleton is the only Manager exported from the package; downstream code (state/, vm/, sync/atomic, tests/warp, plugin/evm/vm.go, plugin/evm/network_handler.go) holds an atomic.Manager (or message.Manager for the wire codec) instead of the legacy codec.Manager. Tx.Sign drops its codec.Manager argument and uses the package-local atomic.Codec singleton. A new Tx.initializeBytes(c Manager) helper re-marshals a freshly-unmarshaled tx through whatever Manager produced the bytes — keeps the atomictest harness disjoint from production Codec while round-tripping correctly. sync/atomic.Summary picks up its own marshal/unmarshal (4 fixed fields, no codec needed) so plugin/evm/message doesn't have to know about syncable summary shape. The secp256k1fx.VM contract still requires codec.Registry — extracted to a new plugin/evm/secpfx/ adapter so the only remaining codec dependency in the atomic-tx universe lives outside plugin/evm/atomic/. Tests pass: plugin/evm/atomic/..., sync/atomic/..., tests/warp/...
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package atomic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/luxfi/coreth/plugin/evm/message"
|
|
"github.com/luxfi/coreth/sync/handlers"
|
|
"github.com/luxfi/coreth/sync/handlers/stats"
|
|
"github.com/luxfi/ids"
|
|
|
|
"github.com/luxfi/geth/metrics"
|
|
"github.com/luxfi/geth/triedb"
|
|
)
|
|
|
|
var (
|
|
_ handlers.LeafRequestHandler = (*uninitializedHandler)(nil)
|
|
|
|
errUninitialized = errors.New("uninitialized handler")
|
|
)
|
|
|
|
type uninitializedHandler struct{}
|
|
|
|
func (h *uninitializedHandler) OnLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest message.LeafsRequest) ([]byte, error) {
|
|
return nil, errUninitialized
|
|
}
|
|
|
|
// atomicLeafHandler is a wrapper around handlers.LeafRequestHandler that allows for initialization after creation
|
|
type leafHandler struct {
|
|
handlers.LeafRequestHandler
|
|
}
|
|
|
|
// NewAtomicLeafHandler returns a new uninitialized leafHandler that can be later initialized
|
|
func NewLeafHandler() *leafHandler {
|
|
return &leafHandler{
|
|
LeafRequestHandler: &uninitializedHandler{},
|
|
}
|
|
}
|
|
|
|
// Initialize initializes the atomicLeafHandler with the provided atomicTrieDB,
|
|
// trieKeyLength, and networkCodec. networkCodec is a [message.Manager] —
|
|
// the wire codec for leaf-sync messages, owned by plugin/evm/message.
|
|
func (a *leafHandler) Initialize(atomicTrieDB *triedb.Database, trieKeyLength int, networkCodec message.Manager) {
|
|
handlerStats := stats.GetOrRegisterHandlerStats(metrics.Enabled())
|
|
a.LeafRequestHandler = handlers.NewLeafsRequestHandler(atomicTrieDB, trieKeyLength, nil, networkCodec, handlerStats)
|
|
}
|