From 2196015bf199fb237a99eec11e8ac48a89aadc6c Mon Sep 17 00:00:00 2001 From: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com> Date: Mon, 11 Mar 2024 09:09:02 -0400 Subject: [PATCH 1/4] Remove Pre-Durango TLS certificate parsing logic (#2831) Co-authored-by: Stephen Buttolph --- chains/manager.go | 17 ++---- indexer/examples/p-chain/main.go | 3 +- indexer/examples/x-chain-blocks/main.go | 3 +- network/certs_test.go | 16 ++++- network/network.go | 10 +--- network/network_test.go | 17 ++++-- network/peer/ip_test.go | 8 +-- network/peer/peer.go | 15 +---- network/peer/peer_test.go | 6 +- network/peer/test_peer.go | 1 - network/peer/upgrader.go | 30 ++-------- node/node.go | 21 ++++--- staking/asn1.go | 7 --- staking/certificate.go | 19 +----- staking/parse.go | 48 ++++++--------- staking/parse_test.go | 74 +++--------------------- staking/verify.go | 52 ----------------- tests/fixture/tmpnet/node.go | 5 +- vms/proposervm/batched_vm.go | 2 +- vms/proposervm/block/block.go | 11 +--- vms/proposervm/block/build.go | 7 +-- vms/proposervm/block/build_test.go | 3 +- vms/proposervm/block/option.go | 4 +- vms/proposervm/block/parse.go | 9 +-- vms/proposervm/block/parse_test.go | 57 ++++++------------ vms/proposervm/state/block_state.go | 7 +-- vms/proposervm/state/block_state_test.go | 28 ++++----- vms/proposervm/vm.go | 2 +- vms/proposervm/vm_test.go | 5 +- 29 files changed, 144 insertions(+), 343 deletions(-) diff --git a/chains/manager.go b/chains/manager.go index 7519982f18bb..6393f7ca58e8 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -6,7 +6,6 @@ package chains import ( "context" "crypto" - "crypto/tls" "errors" "fmt" "os" @@ -173,7 +172,8 @@ type ChainConfig struct { type ManagerConfig struct { SybilProtectionEnabled bool - StakingTLSCert tls.Certificate // needed to sign snowman++ blocks + StakingTLSSigner crypto.Signer + StakingTLSCert *staking.Certificate StakingBLSKey *bls.SecretKey TracingEnabled bool // Must not be used unless [TracingEnabled] is true as this may be nil. @@ -239,9 +239,6 @@ type manager struct { ids.Aliaser ManagerConfig - stakingSigner crypto.Signer - stakingCert *staking.Certificate - // Those notified when a chain is created registrants []Registrant @@ -268,8 +265,6 @@ func New(config *ManagerConfig) Manager { return &manager{ Aliaser: ids.NewAliaser(), ManagerConfig: *config, - stakingSigner: config.StakingTLSCert.PrivateKey.(crypto.Signer), - stakingCert: staking.CertificateFromX509(config.StakingTLSCert.Leaf), chains: make(map[ids.ID]handler.Handler), chainsQueue: buffer.NewUnboundedBlockingDeque[ChainParameters](initialQueueSize), unblockChainCreatorCh: make(chan struct{}), @@ -725,8 +720,8 @@ func (m *manager) createAvalancheChain( MinimumPChainHeight: m.ApricotPhase4MinPChainHeight, MinBlkDelay: minBlockDelay, NumHistoricalBlocks: numHistoricalBlocks, - StakingLeafSigner: m.stakingSigner, - StakingCertLeaf: m.stakingCert, + StakingLeafSigner: m.StakingTLSSigner, + StakingCertLeaf: m.StakingTLSCert, }, ) @@ -1062,8 +1057,8 @@ func (m *manager) createSnowmanChain( MinimumPChainHeight: m.ApricotPhase4MinPChainHeight, MinBlkDelay: minBlockDelay, NumHistoricalBlocks: numHistoricalBlocks, - StakingLeafSigner: m.stakingSigner, - StakingCertLeaf: m.stakingCert, + StakingLeafSigner: m.StakingTLSSigner, + StakingCertLeaf: m.StakingTLSCert, }, ) diff --git a/indexer/examples/p-chain/main.go b/indexer/examples/p-chain/main.go index b690ebf0efb9..8e0c6c4ce026 100644 --- a/indexer/examples/p-chain/main.go +++ b/indexer/examples/p-chain/main.go @@ -9,7 +9,6 @@ import ( "time" "github.com/ava-labs/avalanchego/indexer" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/wallet/subnet/primary" platformvmblock "github.com/ava-labs/avalanchego/vms/platformvm/block" @@ -34,7 +33,7 @@ func main() { } platformvmBlockBytes := container.Bytes - proposerVMBlock, err := proposervmblock.Parse(container.Bytes, version.DefaultUpgradeTime) + proposerVMBlock, err := proposervmblock.Parse(container.Bytes) if err == nil { platformvmBlockBytes = proposerVMBlock.Block() } diff --git a/indexer/examples/x-chain-blocks/main.go b/indexer/examples/x-chain-blocks/main.go index 2687e5a03c68..226460720fc5 100644 --- a/indexer/examples/x-chain-blocks/main.go +++ b/indexer/examples/x-chain-blocks/main.go @@ -9,7 +9,6 @@ import ( "time" "github.com/ava-labs/avalanchego/indexer" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/proposervm/block" "github.com/ava-labs/avalanchego/wallet/chain/x" "github.com/ava-labs/avalanchego/wallet/subnet/primary" @@ -32,7 +31,7 @@ func main() { continue } - proposerVMBlock, err := block.Parse(container.Bytes, version.DefaultUpgradeTime) + proposerVMBlock, err := block.Parse(container.Bytes) if err != nil { log.Fatalf("failed to parse proposervm block: %s\n", err) } diff --git a/network/certs_test.go b/network/certs_test.go index a4b1642b3dca..587674119546 100644 --- a/network/certs_test.go +++ b/network/certs_test.go @@ -58,8 +58,17 @@ func init() { cert1, cert2, cert3, } + stakingCert1, err := staking.ParseCertificate(cert1.Leaf.Raw) + if err != nil { + panic(err) + } + stakingCert2, err := staking.ParseCertificate(cert2.Leaf.Raw) + if err != nil { + panic(err) + } + ip = ips.NewClaimedIPPort( - staking.CertificateFromX509(cert1.Leaf), + stakingCert1, ips.IPPort{ IP: net.IPv4(127, 0, 0, 1), Port: 9651, @@ -68,7 +77,7 @@ func init() { nil, // signature ) otherIP = ips.NewClaimedIPPort( - staking.CertificateFromX509(cert2.Leaf), + stakingCert2, ips.IPPort{ IP: net.IPv4(127, 0, 0, 1), Port: 9651, @@ -94,7 +103,8 @@ func getTLS(t *testing.T, index int) (ids.NodeID, *tls.Certificate, *tls.Config) } tlsCert := tlsCerts[index] - cert := staking.CertificateFromX509(tlsCert.Leaf) + cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) + require.NoError(t, err) nodeID := ids.NodeIDFromCert(cert) return nodeID, tlsCert, tlsConfigs[index] } diff --git a/network/network.go b/network/network.go index a6ac6fdd28b2..5d34458272d2 100644 --- a/network/network.go +++ b/network/network.go @@ -272,12 +272,6 @@ func NewNetwork( IPSigner: peer.NewIPSigner(config.MyIPPort, config.TLSKey, config.BLSKey), } - // Invariant: We delay the activation of durango during the TLS handshake to - // avoid gossiping any TLS certs that anyone else in the network may - // consider invalid. Recall that if a peer gossips an invalid cert, the - // connection is terminated. - durangoTime := version.GetDurangoTime(config.NetworkID) - durangoTimeWithClockSkew := durangoTime.Add(config.MaxClockDifference) onCloseCtx, cancel := context.WithCancel(context.Background()) n := &network{ config: config, @@ -288,8 +282,8 @@ func NewNetwork( inboundConnUpgradeThrottler: throttling.NewInboundConnUpgradeThrottler(log, config.ThrottlerConfig.InboundConnUpgradeThrottlerConfig), listener: listener, dialer: dialer, - serverUpgrader: peer.NewTLSServerUpgrader(config.TLSConfig, metrics.tlsConnRejected, durangoTimeWithClockSkew), - clientUpgrader: peer.NewTLSClientUpgrader(config.TLSConfig, metrics.tlsConnRejected, durangoTimeWithClockSkew), + serverUpgrader: peer.NewTLSServerUpgrader(config.TLSConfig, metrics.tlsConnRejected), + clientUpgrader: peer.NewTLSClientUpgrader(config.TLSConfig, metrics.tlsConnRejected), onCloseCtx: onCloseCtx, onCloseCtxCancel: cancel, diff --git a/network/network_test.go b/network/network_test.go index fb70f2966b2e..447a58df14a2 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -403,9 +403,12 @@ func TestTrackVerifiesSignatures(t *testing.T) { nodeID, tlsCert, _ := getTLS(t, 1) require.NoError(network.config.Validators.AddStaker(constants.PrimaryNetworkID, nodeID, nil, ids.Empty, 1)) - err := network.Track([]*ips.ClaimedIPPort{ + stakingCert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) + require.NoError(err) + + err = network.Track([]*ips.ClaimedIPPort{ ips.NewClaimedIPPort( - staking.CertificateFromX509(tlsCert.Leaf), + stakingCert, ips.IPPort{ IP: net.IPv4(123, 132, 123, 123), Port: 10000, @@ -558,15 +561,17 @@ func TestDialDeletesNonValidators(t *testing.T) { wg.Add(len(networks)) for i, net := range networks { if i != 0 { - err := net.Track([]*ips.ClaimedIPPort{ + stakingCert, err := staking.ParseCertificate(config.TLSConfig.Certificates[0].Leaf.Raw) + require.NoError(err) + + require.NoError(net.Track([]*ips.ClaimedIPPort{ ips.NewClaimedIPPort( - staking.CertificateFromX509(config.TLSConfig.Certificates[0].Leaf), + stakingCert, ip.IPPort, ip.Timestamp, ip.TLSSignature, ), - }) - require.NoError(err) + })) } go func(net Network) { diff --git a/network/peer/ip_test.go b/network/peer/ip_test.go index dd39d5a8a8b9..142d675ecfaa 100644 --- a/network/peer/ip_test.go +++ b/network/peer/ip_test.go @@ -19,16 +19,16 @@ import ( func TestSignedIpVerify(t *testing.T) { tlsCert1, err := staking.NewTLSCert() require.NoError(t, err) - cert1 := staking.CertificateFromX509(tlsCert1.Leaf) - require.NoError(t, staking.ValidateCertificate(cert1)) + cert1, err := staking.ParseCertificate(tlsCert1.Leaf.Raw) + require.NoError(t, err) tlsKey1 := tlsCert1.PrivateKey.(crypto.Signer) blsKey1, err := bls.NewSecretKey() require.NoError(t, err) tlsCert2, err := staking.NewTLSCert() require.NoError(t, err) - cert2 := staking.CertificateFromX509(tlsCert2.Leaf) - require.NoError(t, staking.ValidateCertificate(cert2)) + cert2, err := staking.ParseCertificate(tlsCert2.Leaf.Raw) + require.NoError(t, err) now := time.Now() diff --git a/network/peer/peer.go b/network/peer/peer.go index 97254c75f445..4e9e6b91ceee 100644 --- a/network/peer/peer.go +++ b/network/peer/peer.go @@ -1207,22 +1207,9 @@ func (p *peer) handlePeerList(msg *p2p.PeerList) { close(p.onFinishHandshake) } - // Invariant: We do not account for clock skew here, as the sender of the - // certificate is expected to account for clock skew during the activation - // of Durango. - durangoTime := version.GetDurangoTime(p.NetworkID) - beforeDurango := time.Now().Before(durangoTime) discoveredIPs := make([]*ips.ClaimedIPPort, len(msg.ClaimedIpPorts)) // the peers this peer told us about for i, claimedIPPort := range msg.ClaimedIpPorts { - var ( - tlsCert *staking.Certificate - err error - ) - if beforeDurango { - tlsCert, err = staking.ParseCertificate(claimedIPPort.X509Certificate) - } else { - tlsCert, err = staking.ParseCertificatePermissive(claimedIPPort.X509Certificate) - } + tlsCert, err := staking.ParseCertificate(claimedIPPort.X509Certificate) if err != nil { p.Log.Debug("message with invalid field", zap.Stringer("nodeID", p.id), diff --git a/network/peer/peer_test.go b/network/peer/peer_test.go index 45d2fc60a234..c354013e64cc 100644 --- a/network/peer/peer_test.go +++ b/network/peer/peer_test.go @@ -68,11 +68,13 @@ func makeRawTestPeers(t *testing.T, trackedSubnets set.Set[ids.ID]) (*rawTestPee tlsCert0, err := staking.NewTLSCert() require.NoError(err) - cert0 := staking.CertificateFromX509(tlsCert0.Leaf) + cert0, err := staking.ParseCertificate(tlsCert0.Leaf.Raw) + require.NoError(err) tlsCert1, err := staking.NewTLSCert() require.NoError(err) - cert1 := staking.CertificateFromX509(tlsCert1.Leaf) + cert1, err := staking.ParseCertificate(tlsCert1.Leaf.Raw) + require.NoError(err) nodeID0 := ids.NodeIDFromCert(cert0) nodeID1 := ids.NodeIDFromCert(cert1) diff --git a/network/peer/test_peer.go b/network/peer/test_peer.go index eb1a79476480..0c8762bc44c4 100644 --- a/network/peer/test_peer.go +++ b/network/peer/test_peer.go @@ -66,7 +66,6 @@ func StartTestPeer( clientUpgrader := NewTLSClientUpgrader( tlsConfg, prometheus.NewCounter(prometheus.CounterOpts{}), - version.GetDurangoTime(networkID), ) peerID, conn, cert, err := clientUpgrader.Upgrade(conn) diff --git a/network/peer/upgrader.go b/network/peer/upgrader.go index 9341922175cd..ec39c87136d2 100644 --- a/network/peer/upgrader.go +++ b/network/peer/upgrader.go @@ -7,7 +7,6 @@ import ( "crypto/tls" "errors" "net" - "time" "github.com/prometheus/client_golang/prometheus" @@ -30,40 +29,36 @@ type Upgrader interface { type tlsServerUpgrader struct { config *tls.Config invalidCerts prometheus.Counter - durangoTime time.Time } -func NewTLSServerUpgrader(config *tls.Config, invalidCerts prometheus.Counter, durangoTime time.Time) Upgrader { +func NewTLSServerUpgrader(config *tls.Config, invalidCerts prometheus.Counter) Upgrader { return &tlsServerUpgrader{ config: config, invalidCerts: invalidCerts, - durangoTime: durangoTime, } } func (t *tlsServerUpgrader) Upgrade(conn net.Conn) (ids.NodeID, net.Conn, *staking.Certificate, error) { - return connToIDAndCert(tls.Server(conn, t.config), t.invalidCerts, t.durangoTime) + return connToIDAndCert(tls.Server(conn, t.config), t.invalidCerts) } type tlsClientUpgrader struct { config *tls.Config invalidCerts prometheus.Counter - durangoTime time.Time } -func NewTLSClientUpgrader(config *tls.Config, invalidCerts prometheus.Counter, durangoTime time.Time) Upgrader { +func NewTLSClientUpgrader(config *tls.Config, invalidCerts prometheus.Counter) Upgrader { return &tlsClientUpgrader{ config: config, invalidCerts: invalidCerts, - durangoTime: durangoTime, } } func (t *tlsClientUpgrader) Upgrade(conn net.Conn) (ids.NodeID, net.Conn, *staking.Certificate, error) { - return connToIDAndCert(tls.Client(conn, t.config), t.invalidCerts, t.durangoTime) + return connToIDAndCert(tls.Client(conn, t.config), t.invalidCerts) } -func connToIDAndCert(conn *tls.Conn, invalidCerts prometheus.Counter, durangoTime time.Time) (ids.NodeID, net.Conn, *staking.Certificate, error) { +func connToIDAndCert(conn *tls.Conn, invalidCerts prometheus.Counter) (ids.NodeID, net.Conn, *staking.Certificate, error) { if err := conn.Handshake(); err != nil { return ids.EmptyNodeID, nil, nil, err } @@ -74,20 +69,7 @@ func connToIDAndCert(conn *tls.Conn, invalidCerts prometheus.Counter, durangoTim } tlsCert := state.PeerCertificates[0] - // Invariant: ParseCertificate is used rather than CertificateFromX509 to - // ensure that signature verification can assume the certificate was - // parseable according the staking package's parser. - // - // TODO: Remove pre-Durango parsing after v1.11.x has activated. - var ( - peerCert *staking.Certificate - err error - ) - if time.Now().Before(durangoTime) { - peerCert, err = staking.ParseCertificate(tlsCert.Raw) - } else { - peerCert, err = staking.ParseCertificatePermissive(tlsCert.Raw) - } + peerCert, err := staking.ParseCertificate(tlsCert.Raw) if err != nil { invalidCerts.Inc() return ids.EmptyNodeID, nil, nil, err diff --git a/node/node.go b/node/node.go index 13ae6071cfb0..e214e2165d20 100644 --- a/node/node.go +++ b/node/node.go @@ -110,16 +110,18 @@ func New( logger logging.Logger, ) (*Node, error) { tlsCert := config.StakingTLSCert.Leaf - stakingCert := staking.CertificateFromX509(tlsCert) - if err := staking.ValidateCertificate(stakingCert); err != nil { + stakingCert, err := staking.ParseCertificate(tlsCert.Raw) + if err != nil { return nil, fmt.Errorf("invalid staking certificate: %w", err) } n := &Node{ - Log: logger, - LogFactory: logFactory, - ID: ids.NodeIDFromCert(stakingCert), - Config: config, + Log: logger, + LogFactory: logFactory, + StakingTLSSigner: config.StakingTLSCert.PrivateKey.(crypto.Signer), + StakingTLSCert: stakingCert, + ID: ids.NodeIDFromCert(stakingCert), + Config: config, } n.DoneShuttingDown.Add(1) @@ -134,7 +136,6 @@ func New( zap.Reflect("config", n.Config), ) - var err error n.VMFactoryLog, err = logFactory.Make("vm-factory") if err != nil { return nil, fmt.Errorf("problem creating vm logger: %w", err) @@ -263,6 +264,9 @@ type Node struct { // (in consensus, for example) ID ids.NodeID + StakingTLSSigner crypto.Signer + StakingTLSCert *staking.Certificate + // Storage for this node DB database.Database @@ -1054,7 +1058,8 @@ func (n *Node) initChainManager(avaxAssetID ids.ID) error { n.chainManager = chains.New( &chains.ManagerConfig{ SybilProtectionEnabled: n.Config.SybilProtectionEnabled, - StakingTLSCert: n.Config.StakingTLSCert, + StakingTLSSigner: n.StakingTLSSigner, + StakingTLSCert: n.StakingTLSCert, StakingBLSKey: n.Config.StakingSigningKey, Log: n.Log, LogFactory: n.LogFactory, diff --git a/staking/asn1.go b/staking/asn1.go index afd817a95cd6..6796b900ebe3 100644 --- a/staking/asn1.go +++ b/staking/asn1.go @@ -5,7 +5,6 @@ package staking import ( "crypto" - "crypto/x509" "encoding/asn1" "fmt" @@ -30,12 +29,6 @@ var ( // id-ecPublicKey OBJECT IDENTIFIER ::= { // iso(1) member-body(2) us(840) ansi-X9-62(10045) keyType(2) 1 } oidPublicKeyECDSA = asn1.ObjectIdentifier{1, 2, 840, 10045, 2, 1} - - // Ref: https://github.com/golang/go/blob/go1.19.12/src/crypto/x509/x509.go#L326-L350 - signatureAlgorithmVerificationDetails = map[x509.SignatureAlgorithm]x509.PublicKeyAlgorithm{ - x509.SHA256WithRSA: x509.RSA, - x509.ECDSAWithSHA256: x509.ECDSA, - } ) func init() { diff --git a/staking/certificate.go b/staking/certificate.go index b3e1a511f63f..5032c1fad2cb 100644 --- a/staking/certificate.go +++ b/staking/certificate.go @@ -3,26 +3,9 @@ package staking -import ( - "crypto" - "crypto/x509" -) +import "crypto" type Certificate struct { Raw []byte PublicKey crypto.PublicKey - // TODO: Remove after v1.11.x activates. - SignatureAlgorithm x509.SignatureAlgorithm -} - -// CertificateFromX509 converts an x509 certificate into a staking certificate. -// -// Invariant: The provided certificate must be a parseable into a staking -// certificate. -func CertificateFromX509(cert *x509.Certificate) *Certificate { - return &Certificate{ - Raw: cert.Raw, - PublicKey: cert.PublicKey, - SignatureAlgorithm: cert.SignatureAlgorithm, - } } diff --git a/staking/parse.go b/staking/parse.go index 4f9a50f05131..28ae02cbc644 100644 --- a/staking/parse.go +++ b/staking/parse.go @@ -8,7 +8,6 @@ import ( "crypto/ecdsa" "crypto/elliptic" "crypto/rsa" - "crypto/x509" "encoding/asn1" "errors" "fmt" @@ -53,25 +52,13 @@ var ( ErrUnknownPublicKeyAlgorithm = errors.New("staking: unknown public key algorithm") ) -// ParseCertificate parses a single certificate from the given ASN.1 DER data. -// -// TODO: Remove after v1.11.x activates. -func ParseCertificate(der []byte) (*Certificate, error) { - x509Cert, err := x509.ParseCertificate(der) - if err != nil { - return nil, err - } - stakingCert := CertificateFromX509(x509Cert) - return stakingCert, ValidateCertificate(stakingCert) -} - -// ParseCertificatePermissive parses a single certificate from the given ASN.1. +// ParseCertificate parses a single certificate from the given ASN.1. // // This function does not validate that the certificate is valid to be used // against normal TLS implementations. // // Ref: https://github.com/golang/go/blob/go1.19.12/src/crypto/x509/parser.go#L789-L968 -func ParseCertificatePermissive(bytes []byte) (*Certificate, error) { +func ParseCertificate(bytes []byte) (*Certificate, error) { if len(bytes) > MaxCertificateLen { return nil, ErrCertificateTooLarge } @@ -126,56 +113,55 @@ func ParseCertificatePermissive(bytes []byte) (*Certificate, error) { if !input.ReadASN1BitString(&spk) { return nil, ErrMalformedSubjectPublicKey } - publicKey, signatureAlgorithm, err := parsePublicKey(pkAI, spk) + publicKey, err := parsePublicKey(pkAI, spk) return &Certificate{ - Raw: bytes, - SignatureAlgorithm: signatureAlgorithm, - PublicKey: publicKey, + Raw: bytes, + PublicKey: publicKey, }, err } // Ref: https://github.com/golang/go/blob/go1.19.12/src/crypto/x509/parser.go#L215-L306 -func parsePublicKey(oid asn1.ObjectIdentifier, publicKey asn1.BitString) (crypto.PublicKey, x509.SignatureAlgorithm, error) { +func parsePublicKey(oid asn1.ObjectIdentifier, publicKey asn1.BitString) (crypto.PublicKey, error) { der := cryptobyte.String(publicKey.RightAlign()) switch { case oid.Equal(oidPublicKeyRSA): pub := &rsa.PublicKey{N: new(big.Int)} if !der.ReadASN1(&der, cryptobyte_asn1.SEQUENCE) { - return nil, 0, ErrInvalidRSAPublicKey + return nil, ErrInvalidRSAPublicKey } if !der.ReadASN1Integer(pub.N) { - return nil, 0, ErrInvalidRSAModulus + return nil, ErrInvalidRSAModulus } if !der.ReadASN1Integer(&pub.E) { - return nil, 0, ErrInvalidRSAPublicExponent + return nil, ErrInvalidRSAPublicExponent } if pub.N.Sign() <= 0 { - return nil, 0, ErrRSAModulusNotPositive + return nil, ErrRSAModulusNotPositive } if bitLen := pub.N.BitLen(); bitLen != allowedRSALargeModulusLen && bitLen != allowedRSASmallModulusLen { - return nil, 0, fmt.Errorf("%w: %d", ErrUnsupportedRSAModulusBitLen, bitLen) + return nil, fmt.Errorf("%w: %d", ErrUnsupportedRSAModulusBitLen, bitLen) } if pub.N.Bit(0) == 0 { - return nil, 0, ErrRSAModulusIsEven + return nil, ErrRSAModulusIsEven } if pub.E != allowedRSAPublicExponentValue { - return nil, 0, fmt.Errorf("%w: %d", ErrUnsupportedRSAPublicExponent, pub.E) + return nil, fmt.Errorf("%w: %d", ErrUnsupportedRSAPublicExponent, pub.E) } - return pub, x509.SHA256WithRSA, nil + return pub, nil case oid.Equal(oidPublicKeyECDSA): namedCurve := elliptic.P256() x, y := elliptic.Unmarshal(namedCurve, der) if x == nil { - return nil, 0, ErrFailedUnmarshallingEllipticCurvePoint + return nil, ErrFailedUnmarshallingEllipticCurvePoint } return &ecdsa.PublicKey{ Curve: namedCurve, X: x, Y: y, - }, x509.ECDSAWithSHA256, nil + }, nil default: - return nil, 0, ErrUnknownPublicKeyAlgorithm + return nil, ErrUnknownPublicKeyAlgorithm } } diff --git a/staking/parse_test.go b/staking/parse_test.go index 60f6ee8f3240..41704e3b71dc 100644 --- a/staking/parse_test.go +++ b/staking/parse_test.go @@ -11,32 +11,12 @@ import ( _ "embed" ) -var ( - //go:embed large_rsa_key.cert - largeRSAKeyCert []byte - - parsers = []struct { - name string - parse func([]byte) (*Certificate, error) - }{ - { - name: "ParseCertificate", - parse: ParseCertificate, - }, - { - name: "ParseCertificatePermissive", - parse: ParseCertificatePermissive, - }, - } -) +//go:embed large_rsa_key.cert +var largeRSAKeyCert []byte func TestParseCheckLargeCert(t *testing.T) { - for _, parser := range parsers { - t.Run(parser.name, func(t *testing.T) { - _, err := parser.parse(largeRSAKeyCert) - require.ErrorIs(t, err, ErrCertificateTooLarge) - }) - } + _, err := ParseCertificate(largeRSAKeyCert) + require.ErrorIs(t, err, ErrCertificateTooLarge) } func BenchmarkParse(b *testing.B) { @@ -44,46 +24,10 @@ func BenchmarkParse(b *testing.B) { require.NoError(b, err) bytes := tlsCert.Leaf.Raw - for _, parser := range parsers { - b.Run(parser.name, func(b *testing.B) { - for i := 0; i < b.N; i++ { - _, err = parser.parse(bytes) - require.NoError(b, err) - } - }) - } -} -func FuzzParseCertificate(f *testing.F) { - tlsCert, err := NewTLSCert() - require.NoError(f, err) - - f.Add(tlsCert.Leaf.Raw) - f.Add(largeRSAKeyCert) - f.Fuzz(func(t *testing.T, certBytes []byte) { - require := require.New(t) - - // Verify that any certificate that can be parsed by ParseCertificate - // can also be parsed by ParseCertificatePermissive. - { - strictCert, err := ParseCertificate(certBytes) - if err == nil { - permissiveCert, err := ParseCertificatePermissive(certBytes) - require.NoError(err) - require.Equal(strictCert, permissiveCert) - } - } - - // Verify that any certificate that can't be parsed by - // ParseCertificatePermissive also can't be parsed by ParseCertificate. - { - cert, err := ParseCertificatePermissive(certBytes) - if err == nil { - require.NoError(ValidateCertificate(cert)) - } else { - _, err = ParseCertificate(certBytes) - require.Error(err) //nolint:forbidigo - } - } - }) + b.ResetTimer() + for i := 0; i < b.N; i++ { + _, err = ParseCertificate(bytes) + require.NoError(b, err) + } } diff --git a/staking/verify.go b/staking/verify.go index dd4255455ff0..450daf4e92f4 100644 --- a/staking/verify.go +++ b/staking/verify.go @@ -6,17 +6,12 @@ package staking import ( "crypto" "crypto/ecdsa" - "crypto/elliptic" "crypto/rsa" - "crypto/x509" "errors" - "fmt" ) var ( ErrUnsupportedAlgorithm = errors.New("staking: cannot verify signature: unsupported algorithm") - ErrPublicKeyAlgoMismatch = errors.New("staking: signature algorithm specified different public key type") - ErrInvalidECDSAPublicKey = errors.New("staking: invalid ECDSA public key") ErrECDSAVerificationFailure = errors.New("staking: ECDSA verification failure") ) @@ -45,50 +40,3 @@ func CheckSignature(cert *Certificate, msg []byte, signature []byte) error { return ErrUnsupportedAlgorithm } } - -// ValidateCertificate verifies that this certificate conforms to the required -// staking format assuming that it was already able to be parsed. -// -// TODO: Remove after v1.11.x activates. -func ValidateCertificate(cert *Certificate) error { - if len(cert.Raw) > MaxCertificateLen { - return ErrCertificateTooLarge - } - - pubkeyAlgo, ok := signatureAlgorithmVerificationDetails[cert.SignatureAlgorithm] - if !ok { - return ErrUnsupportedAlgorithm - } - - switch pub := cert.PublicKey.(type) { - case *rsa.PublicKey: - if pubkeyAlgo != x509.RSA { - return signaturePublicKeyAlgoMismatchError(pubkeyAlgo, pub) - } - if bitLen := pub.N.BitLen(); bitLen != allowedRSALargeModulusLen && bitLen != allowedRSASmallModulusLen { - return fmt.Errorf("%w: %d", ErrUnsupportedRSAModulusBitLen, bitLen) - } - if pub.N.Bit(0) == 0 { - return ErrRSAModulusIsEven - } - if pub.E != allowedRSAPublicExponentValue { - return fmt.Errorf("%w: %d", ErrUnsupportedRSAPublicExponent, pub.E) - } - return nil - case *ecdsa.PublicKey: - if pubkeyAlgo != x509.ECDSA { - return signaturePublicKeyAlgoMismatchError(pubkeyAlgo, pub) - } - if pub.Curve != elliptic.P256() { - return ErrInvalidECDSAPublicKey - } - return nil - default: - return ErrUnsupportedAlgorithm - } -} - -// Ref: https://github.com/golang/go/blob/go1.19.12/src/crypto/x509/x509.go#L812-L814 -func signaturePublicKeyAlgoMismatchError(expectedPubKeyAlgo x509.PublicKeyAlgorithm, pubKey any) error { - return fmt.Errorf("%w: expected an %s public key, but have public key of type %T", ErrPublicKeyAlgoMismatch, expectedPubKeyAlgo, pubKey) -} diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index f725730ced37..99c0aeb3ebce 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -330,7 +330,10 @@ func (n *Node) EnsureNodeID() error { if err != nil { return fmt.Errorf("failed to ensure node ID: failed to load tls cert: %w", err) } - stakingCert := staking.CertificateFromX509(tlsCert.Leaf) + stakingCert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) + if err != nil { + return fmt.Errorf("failed to ensure node ID: failed to parse staking cert: %w", err) + } n.NodeID = ids.NodeIDFromCert(stakingCert) return nil diff --git a/vms/proposervm/batched_vm.go b/vms/proposervm/batched_vm.go index 0bf514827193..ff1ce6a597a0 100644 --- a/vms/proposervm/batched_vm.go +++ b/vms/proposervm/batched_vm.go @@ -101,7 +101,7 @@ func (vm *VM) BatchedParseBlock(ctx context.Context, blks [][]byte) ([]snowman.B ) for ; blocksIndex < len(blks); blocksIndex++ { blkBytes := blks[blocksIndex] - statelessBlock, err := statelessblock.Parse(blkBytes, vm.DurangoTime) + statelessBlock, err := statelessblock.Parse(blkBytes) if err != nil { break } diff --git a/vms/proposervm/block/block.go b/vms/proposervm/block/block.go index 0f5b374391f7..d99a569c96f6 100644 --- a/vms/proposervm/block/block.go +++ b/vms/proposervm/block/block.go @@ -28,7 +28,7 @@ type Block interface { Block() []byte Bytes() []byte - initialize(bytes []byte, durangoTime time.Time) error + initialize(bytes []byte) error } type SignedBlock interface { @@ -76,7 +76,7 @@ func (b *statelessBlock) Bytes() []byte { return b.bytes } -func (b *statelessBlock) initialize(bytes []byte, durangoTime time.Time) error { +func (b *statelessBlock) initialize(bytes []byte) error { b.bytes = bytes // The serialized form of the block is the unsignedBytes followed by the @@ -91,13 +91,8 @@ func (b *statelessBlock) initialize(bytes []byte, durangoTime time.Time) error { return nil } - // TODO: Remove durangoTime after v1.11.x has activated. var err error - if b.timestamp.Before(durangoTime) { - b.cert, err = staking.ParseCertificate(b.StatelessBlock.Certificate) - } else { - b.cert, err = staking.ParseCertificatePermissive(b.StatelessBlock.Certificate) - } + b.cert, err = staking.ParseCertificate(b.StatelessBlock.Certificate) if err != nil { return fmt.Errorf("%w: %w", errInvalidCertificate, err) } diff --git a/vms/proposervm/block/build.go b/vms/proposervm/block/build.go index b13255c91dd1..228ab97604da 100644 --- a/vms/proposervm/block/build.go +++ b/vms/proposervm/block/build.go @@ -36,9 +36,7 @@ func BuildUnsigned( return nil, err } - // Invariant: The durango timestamp isn't used here because the certificate - // is empty. - return block, block.initialize(bytes, time.Time{}) + return block, block.initialize(bytes) } func Build( @@ -125,6 +123,5 @@ func BuildOption( return nil, err } - // Invariant: The durango timestamp isn't used. - return block, block.initialize(bytes, time.Time{}) + return block, block.initialize(bytes) } diff --git a/vms/proposervm/block/build_test.go b/vms/proposervm/block/build_test.go index 8388e8a434f8..5589a9ac95bb 100644 --- a/vms/proposervm/block/build_test.go +++ b/vms/proposervm/block/build_test.go @@ -26,7 +26,8 @@ func TestBuild(t *testing.T) { tlsCert, err := staking.NewTLSCert() require.NoError(err) - cert := staking.CertificateFromX509(tlsCert.Leaf) + cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) + require.NoError(err) key := tlsCert.PrivateKey.(crypto.Signer) builtBlock, err := Build( diff --git a/vms/proposervm/block/option.go b/vms/proposervm/block/option.go index 7edb39bd429f..c80651b621fc 100644 --- a/vms/proposervm/block/option.go +++ b/vms/proposervm/block/option.go @@ -4,8 +4,6 @@ package block import ( - "time" - "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/hashing" ) @@ -34,7 +32,7 @@ func (b *option) Bytes() []byte { return b.bytes } -func (b *option) initialize(bytes []byte, _ time.Time) error { +func (b *option) initialize(bytes []byte) error { b.id = hashing.ComputeHash256Array(bytes) b.bytes = bytes return nil diff --git a/vms/proposervm/block/parse.go b/vms/proposervm/block/parse.go index bf9b44adf1f4..cf275134d888 100644 --- a/vms/proposervm/block/parse.go +++ b/vms/proposervm/block/parse.go @@ -3,12 +3,9 @@ package block -import ( - "fmt" - "time" -) +import "fmt" -func Parse(bytes []byte, durangoTime time.Time) (Block, error) { +func Parse(bytes []byte) (Block, error) { var block Block parsedVersion, err := Codec.Unmarshal(bytes, &block) if err != nil { @@ -17,7 +14,7 @@ func Parse(bytes []byte, durangoTime time.Time) (Block, error) { if parsedVersion != CodecVersion { return nil, fmt.Errorf("expected codec version %d but got %d", CodecVersion, parsedVersion) } - return block, block.initialize(bytes, durangoTime) + return block, block.initialize(bytes) } func ParseHeader(bytes []byte) (Header, error) { diff --git a/vms/proposervm/block/parse_test.go b/vms/proposervm/block/parse_test.go index 148bac82c0a6..e894c1e7a058 100644 --- a/vms/proposervm/block/parse_test.go +++ b/vms/proposervm/block/parse_test.go @@ -28,7 +28,8 @@ func TestParse(t *testing.T) { tlsCert, err := staking.NewTLSCert() require.NoError(err) - cert := staking.CertificateFromX509(tlsCert.Leaf) + cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) + require.NoError(err) key := tlsCert.PrivateKey.(crypto.Signer) builtBlock, err := Build( @@ -43,19 +44,13 @@ func TestParse(t *testing.T) { require.NoError(err) builtBlockBytes := builtBlock.Bytes() - durangoTimes := []time.Time{ - timestamp.Add(time.Second), // Durango not activated yet - timestamp.Add(-time.Second), // Durango activated - } - for _, durangoTime := range durangoTimes { - parsedBlockIntf, err := Parse(builtBlockBytes, durangoTime) - require.NoError(err) - - parsedBlock, ok := parsedBlockIntf.(SignedBlock) - require.True(ok) - - equal(require, chainID, builtBlock, parsedBlock) - } + parsedBlockIntf, err := Parse(builtBlockBytes) + require.NoError(err) + + parsedBlock, ok := parsedBlockIntf.(SignedBlock) + require.True(ok) + + equal(require, chainID, builtBlock, parsedBlock) } func TestParseDuplicateExtension(t *testing.T) { @@ -65,15 +60,7 @@ func TestParseDuplicateExtension(t *testing.T) { blockBytes, err := hex.DecodeString(blockHex) require.NoError(err) - // Note: The above blockHex specifies 123 as the block's timestamp. - timestamp := time.Unix(123, 0) - durangoNotYetActivatedTime := timestamp.Add(time.Second) - durangoAlreadyActivatedTime := timestamp.Add(-time.Second) - - _, err = Parse(blockBytes, durangoNotYetActivatedTime) - require.ErrorIs(err, errInvalidCertificate) - - _, err = Parse(blockBytes, durangoAlreadyActivatedTime) + _, err = Parse(blockBytes) require.NoError(err) } @@ -110,7 +97,7 @@ func TestParseOption(t *testing.T) { builtOptionBytes := builtOption.Bytes() - parsedOption, err := Parse(builtOptionBytes, time.Time{}) + parsedOption, err := Parse(builtOptionBytes) require.NoError(err) equalOption(require, builtOption, parsedOption) @@ -128,19 +115,13 @@ func TestParseUnsigned(t *testing.T) { require.NoError(err) builtBlockBytes := builtBlock.Bytes() - durangoTimes := []time.Time{ - timestamp.Add(time.Second), // Durango not activated yet - timestamp.Add(-time.Second), // Durango activated - } - for _, durangoTime := range durangoTimes { - parsedBlockIntf, err := Parse(builtBlockBytes, durangoTime) - require.NoError(err) - - parsedBlock, ok := parsedBlockIntf.(SignedBlock) - require.True(ok) - - equal(require, ids.Empty, builtBlock, parsedBlock) - } + parsedBlockIntf, err := Parse(builtBlockBytes) + require.NoError(err) + + parsedBlock, ok := parsedBlockIntf.(SignedBlock) + require.True(ok) + + equal(require, ids.Empty, builtBlock, parsedBlock) } func TestParseGibberish(t *testing.T) { @@ -148,6 +129,6 @@ func TestParseGibberish(t *testing.T) { bytes := []byte{0, 1, 2, 3, 4, 5} - _, err := Parse(bytes, time.Time{}) + _, err := Parse(bytes) require.ErrorIs(err, codec.ErrUnknownVersion) } diff --git a/vms/proposervm/state/block_state.go b/vms/proposervm/state/block_state.go index 0c5e210a8d81..64a588851686 100644 --- a/vms/proposervm/state/block_state.go +++ b/vms/proposervm/state/block_state.go @@ -17,7 +17,6 @@ import ( "github.com/ava-labs/avalanchego/utils/metric" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/utils/wrappers" - "github.com/ava-labs/avalanchego/version" "github.com/ava-labs/avalanchego/vms/proposervm/block" ) @@ -110,11 +109,7 @@ func (s *blockState) GetBlock(blkID ids.ID) (block.Block, choices.Status, error) } // The key was in the database - // - // Invariant: Blocks stored on disk were previously accepted by this node. - // Because the durango activation relaxes TLS cert parsing rules, we assume - // it is always activated here. - blk, err := block.Parse(blkWrapper.Block, version.DefaultUpgradeTime) + blk, err := block.Parse(blkWrapper.Block) if err != nil { return nil, choices.Unknown, err } diff --git a/vms/proposervm/state/block_state_test.go b/vms/proposervm/state/block_state_test.go index 269d7fbddc2e..33a43c5febae 100644 --- a/vms/proposervm/state/block_state_test.go +++ b/vms/proposervm/state/block_state_test.go @@ -19,7 +19,7 @@ import ( "github.com/ava-labs/avalanchego/vms/proposervm/block" ) -func testBlockState(a *require.Assertions, bs BlockState) { +func testBlockState(require *require.Assertions, bs BlockState) { parentID := ids.ID{1} timestamp := time.Unix(123, 0) pChainHeight := uint64(2) @@ -27,9 +27,10 @@ func testBlockState(a *require.Assertions, bs BlockState) { chainID := ids.ID{4} tlsCert, err := staking.NewTLSCert() - a.NoError(err) + require.NoError(err) - cert := staking.CertificateFromX509(tlsCert.Leaf) + cert, err := staking.ParseCertificate(tlsCert.Leaf.Raw) + require.NoError(err) key := tlsCert.PrivateKey.(crypto.Signer) b, err := block.Build( @@ -41,26 +42,25 @@ func testBlockState(a *require.Assertions, bs BlockState) { chainID, key, ) - a.NoError(err) + require.NoError(err) _, _, err = bs.GetBlock(b.ID()) - a.Equal(database.ErrNotFound, err) + require.Equal(database.ErrNotFound, err) _, _, err = bs.GetBlock(b.ID()) - a.Equal(database.ErrNotFound, err) + require.Equal(database.ErrNotFound, err) - err = bs.PutBlock(b, choices.Accepted) - a.NoError(err) + require.NoError(bs.PutBlock(b, choices.Accepted)) fetchedBlock, fetchedStatus, err := bs.GetBlock(b.ID()) - a.NoError(err) - a.Equal(choices.Accepted, fetchedStatus) - a.Equal(b.Bytes(), fetchedBlock.Bytes()) + require.NoError(err) + require.Equal(choices.Accepted, fetchedStatus) + require.Equal(b.Bytes(), fetchedBlock.Bytes()) fetchedBlock, fetchedStatus, err = bs.GetBlock(b.ID()) - a.NoError(err) - a.Equal(choices.Accepted, fetchedStatus) - a.Equal(b.Bytes(), fetchedBlock.Bytes()) + require.NoError(err) + require.Equal(choices.Accepted, fetchedStatus) + require.Equal(b.Bytes(), fetchedBlock.Bytes()) } func TestBlockState(t *testing.T) { diff --git a/vms/proposervm/vm.go b/vms/proposervm/vm.go index 488dc984dad1..d2add4c616aa 100644 --- a/vms/proposervm/vm.go +++ b/vms/proposervm/vm.go @@ -693,7 +693,7 @@ func (vm *VM) setLastAcceptedMetadata(ctx context.Context) error { } func (vm *VM) parsePostForkBlock(ctx context.Context, b []byte) (PostForkBlock, error) { - statelessBlock, err := statelessblock.Parse(b, vm.DurangoTime) + statelessBlock, err := statelessblock.Parse(b) if err != nil { return nil, err } diff --git a/vms/proposervm/vm_test.go b/vms/proposervm/vm_test.go index 7ad266d73de7..9e6be32026c5 100644 --- a/vms/proposervm/vm_test.go +++ b/vms/proposervm/vm_test.go @@ -67,7 +67,10 @@ func init() { panic(err) } pTestSigner = tlsCert.PrivateKey.(crypto.Signer) - pTestCert = staking.CertificateFromX509(tlsCert.Leaf) + pTestCert, err = staking.ParseCertificate(tlsCert.Leaf.Raw) + if err != nil { + panic(err) + } } func initTestProposerVM( From 6ec6a62b7fd2adb6101b66d5aaa2352981fd6322 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Mon, 11 Mar 2024 09:09:23 -0400 Subject: [PATCH 2/4] Remove Durango codec check (#2818) --- api/keystore/codec.go | 4 +- chains/atomic/codec.go | 3 +- codec/hierarchycodec/codec.go | 14 ++---- codec/hierarchycodec/codec_test.go | 22 ++------- codec/linearcodec/codec.go | 25 +++------- codec/linearcodec/codec_test.go | 22 ++------- codec/reflectcodec/type_codec.go | 43 ++--------------- codec/test_codec.go | 41 +--------------- database/encdb/codec.go | 4 +- database/linkeddb/codec.go | 3 +- genesis/genesis.go | 1 - go.mod | 2 +- go.sum | 4 +- indexer/codec.go | 3 +- node/node.go | 16 +------ snow/engine/avalanche/vertex/codec.go | 6 +-- vms/avm/block/block_test.go | 2 - vms/avm/block/builder/builder_test.go | 1 - vms/avm/block/parser.go | 8 ++-- vms/avm/config/config.go | 5 -- vms/avm/environment_test.go | 2 - vms/avm/network/gossip_test.go | 6 +-- vms/avm/network/network_test.go | 2 - vms/avm/state/state_test.go | 1 - vms/avm/static_service.go | 2 - vms/avm/txs/base_tx_test.go | 2 - vms/avm/txs/create_asset_tx_test.go | 3 -- vms/avm/txs/executor/executor_test.go | 4 -- .../txs/executor/semantic_verifier_test.go | 5 -- .../txs/executor/syntactic_verifier_test.go | 6 --- vms/avm/txs/export_tx_test.go | 2 - vms/avm/txs/import_tx_test.go | 2 - vms/avm/txs/initial_state_test.go | 13 +++-- vms/avm/txs/operation_test.go | 3 +- vms/avm/txs/parser.go | 9 ++-- vms/avm/vm.go | 1 - vms/components/avax/asset_test.go | 3 +- vms/components/avax/transferables_test.go | 9 ++-- vms/components/avax/utxo_fetching_test.go | 5 +- vms/components/avax/utxo_id_test.go | 3 +- vms/components/avax/utxo_state_test.go | 3 +- vms/components/avax/utxo_test.go | 3 +- vms/components/keystore/codec.go | 5 +- vms/example/xsvm/tx/codec.go | 3 +- vms/nftfx/fx_test.go | 32 ++++++------- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/block/codec.go | 31 ++++-------- vms/platformvm/block/executor/helpers_test.go | 2 +- vms/platformvm/state/metadata_codec.go | 5 +- vms/platformvm/txs/codec.go | 31 ++++-------- vms/platformvm/txs/executor/helpers_test.go | 2 +- vms/platformvm/vm.go | 2 +- vms/platformvm/warp/codec.go | 3 +- vms/platformvm/warp/payload/codec.go | 4 +- vms/propertyfx/fx_test.go | 26 +++++----- vms/proposervm/block/codec.go | 3 +- vms/proposervm/state/codec.go | 3 +- vms/proposervm/summary/codec.go | 3 +- vms/secp256k1fx/credential_test.go | 3 +- vms/secp256k1fx/fx_test.go | 48 +++++++++---------- vms/secp256k1fx/transfer_input_test.go | 3 +- vms/secp256k1fx/transfer_output_test.go | 3 +- wallet/chain/x/constants.go | 3 -- 63 files changed, 145 insertions(+), 390 deletions(-) diff --git a/api/keystore/codec.go b/api/keystore/codec.go index b925747c44ec..3f6df0cf765f 100644 --- a/api/keystore/codec.go +++ b/api/keystore/codec.go @@ -4,8 +4,6 @@ package keystore import ( - "time" - "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/utils/units" @@ -20,7 +18,7 @@ const ( var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewManager(maxPackerSize) if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { panic(err) diff --git a/chains/atomic/codec.go b/chains/atomic/codec.go index 290713b3c258..f53fac8c3f80 100644 --- a/chains/atomic/codec.go +++ b/chains/atomic/codec.go @@ -5,7 +5,6 @@ package atomic import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -17,7 +16,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewManager(math.MaxInt) if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { panic(err) diff --git a/codec/hierarchycodec/codec.go b/codec/hierarchycodec/codec.go index db2ffed0425d..b317a5a4006c 100644 --- a/codec/hierarchycodec/codec.go +++ b/codec/hierarchycodec/codec.go @@ -7,7 +7,6 @@ import ( "fmt" "reflect" "sync" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/reflectcodec" @@ -15,11 +14,6 @@ import ( "github.com/ava-labs/avalanchego/utils/wrappers" ) -const ( - // default max length of a slice being marshalled by Marshal(). Should be <= math.MaxUint32. - defaultMaxSliceLength = 256 * 1024 -) - var ( _ Codec = (*hierarchyCodec)(nil) _ codec.Codec = (*hierarchyCodec)(nil) @@ -51,19 +45,19 @@ type hierarchyCodec struct { } // New returns a new, concurrency-safe codec -func New(durangoTime time.Time, tagNames []string, maxSliceLen uint32) Codec { +func New(tagNames []string) Codec { hCodec := &hierarchyCodec{ currentGroupID: 0, nextTypeID: 0, registeredTypes: bimap.New[typeID, reflect.Type](), } - hCodec.Codec = reflectcodec.New(hCodec, tagNames, durangoTime, maxSliceLen) + hCodec.Codec = reflectcodec.New(hCodec, tagNames) return hCodec } // NewDefault returns a new codec with reasonable default values -func NewDefault(durangoTime time.Time) Codec { - return New(durangoTime, []string{reflectcodec.DefaultTagName}, defaultMaxSliceLength) +func NewDefault() Codec { + return New([]string{reflectcodec.DefaultTagName}) } // SkipRegistrations some number of type IDs diff --git a/codec/hierarchycodec/codec_test.go b/codec/hierarchycodec/codec_test.go index 8149cdcc65e2..a5dd8b5fd546 100644 --- a/codec/hierarchycodec/codec_test.go +++ b/codec/hierarchycodec/codec_test.go @@ -5,41 +5,25 @@ package hierarchycodec import ( "testing" - "time" "github.com/ava-labs/avalanchego/codec" - "github.com/ava-labs/avalanchego/utils/timer/mockable" ) func TestVectors(t *testing.T) { for _, test := range codec.Tests { - c := NewDefault(mockable.MaxTime) + c := NewDefault() test(c, t) } } func TestMultipleTags(t *testing.T) { for _, test := range codec.MultipleTagsTests { - c := New(mockable.MaxTime, []string{"tag1", "tag2"}, defaultMaxSliceLength) - test(c, t) - } -} - -func TestEnforceSliceLen(t *testing.T) { - for _, test := range codec.EnforceSliceLenTests { - c := NewDefault(mockable.MaxTime) - test(c, t) - } -} - -func TestIgnoreSliceLen(t *testing.T) { - for _, test := range codec.IgnoreSliceLenTests { - c := NewDefault(time.Time{}) + c := New([]string{"tag1", "tag2"}) test(c, t) } } func FuzzStructUnmarshalHierarchyCodec(f *testing.F) { - c := NewDefault(mockable.MaxTime) + c := NewDefault() codec.FuzzStructUnmarshal(c, f) } diff --git a/codec/linearcodec/codec.go b/codec/linearcodec/codec.go index 6ad36b8a197d..f690d1354fca 100644 --- a/codec/linearcodec/codec.go +++ b/codec/linearcodec/codec.go @@ -7,7 +7,6 @@ import ( "fmt" "reflect" "sync" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/reflectcodec" @@ -15,11 +14,6 @@ import ( "github.com/ava-labs/avalanchego/utils/wrappers" ) -const ( - // default max length of a slice being marshalled by Marshal(). Should be <= math.MaxUint32. - DefaultMaxSliceLength = 256 * 1024 -) - var ( _ Codec = (*linearCodec)(nil) _ codec.Codec = (*linearCodec)(nil) @@ -43,25 +37,20 @@ type linearCodec struct { registeredTypes *bimap.BiMap[uint32, reflect.Type] } -// New returns a new, concurrency-safe codec; it allow to specify -// both tagNames and maxSlicelenght -func New(durangoTime time.Time, tagNames []string, maxSliceLen uint32) Codec { +// New returns a new, concurrency-safe codec; it allow to specify tagNames. +func New(tagNames []string) Codec { hCodec := &linearCodec{ nextTypeID: 0, registeredTypes: bimap.New[uint32, reflect.Type](), } - hCodec.Codec = reflectcodec.New(hCodec, tagNames, durangoTime, maxSliceLen) + hCodec.Codec = reflectcodec.New(hCodec, tagNames) return hCodec } -// NewDefault is a convenience constructor; it returns a new codec with reasonable default values -func NewDefault(durangoTime time.Time) Codec { - return New(durangoTime, []string{reflectcodec.DefaultTagName}, DefaultMaxSliceLength) -} - -// NewCustomMaxLength is a convenience constructor; it returns a new codec with custom max length and default tags -func NewCustomMaxLength(durangoTime time.Time, maxSliceLen uint32) Codec { - return New(durangoTime, []string{reflectcodec.DefaultTagName}, maxSliceLen) +// NewDefault is a convenience constructor; it returns a new codec with default +// tagNames. +func NewDefault() Codec { + return New([]string{reflectcodec.DefaultTagName}) } // Skip some number of type IDs diff --git a/codec/linearcodec/codec_test.go b/codec/linearcodec/codec_test.go index 3d2f3efff68a..20b886f9cb62 100644 --- a/codec/linearcodec/codec_test.go +++ b/codec/linearcodec/codec_test.go @@ -5,41 +5,25 @@ package linearcodec import ( "testing" - "time" "github.com/ava-labs/avalanchego/codec" - "github.com/ava-labs/avalanchego/utils/timer/mockable" ) func TestVectors(t *testing.T) { for _, test := range codec.Tests { - c := NewDefault(mockable.MaxTime) + c := NewDefault() test(c, t) } } func TestMultipleTags(t *testing.T) { for _, test := range codec.MultipleTagsTests { - c := New(mockable.MaxTime, []string{"tag1", "tag2"}, DefaultMaxSliceLength) - test(c, t) - } -} - -func TestEnforceSliceLen(t *testing.T) { - for _, test := range codec.EnforceSliceLenTests { - c := NewDefault(mockable.MaxTime) - test(c, t) - } -} - -func TestIgnoreSliceLen(t *testing.T) { - for _, test := range codec.IgnoreSliceLenTests { - c := NewDefault(time.Time{}) + c := New([]string{"tag1", "tag2"}) test(c, t) } } func FuzzStructUnmarshalLinearCodec(f *testing.F) { - c := NewDefault(mockable.MaxTime) + c := NewDefault() codec.FuzzStructUnmarshal(c, f) } diff --git a/codec/reflectcodec/type_codec.go b/codec/reflectcodec/type_codec.go index 31243b2594ae..3306f9ccbd7c 100644 --- a/codec/reflectcodec/type_codec.go +++ b/codec/reflectcodec/type_codec.go @@ -10,7 +10,6 @@ import ( "math" "reflect" "slices" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/utils/set" @@ -71,19 +70,15 @@ type TypeCodec interface { // 6. Serialized fields must be exported // 7. nil slices are marshaled as empty slices type genericCodec struct { - typer TypeCodec - durangoTime time.Time // Time after which [maxSliceLen] will be ignored - maxSliceLen uint32 - fielder StructFielder + typer TypeCodec + fielder StructFielder } // New returns a new, concurrency-safe codec -func New(typer TypeCodec, tagNames []string, durangoTime time.Time, maxSliceLen uint32) codec.Codec { +func New(typer TypeCodec, tagNames []string) codec.Codec { return &genericCodec{ - typer: typer, - durangoTime: durangoTime, - maxSliceLen: maxSliceLen, - fielder: NewStructFielder(tagNames), + typer: typer, + fielder: NewStructFielder(tagNames), } } @@ -378,13 +373,6 @@ func (c *genericCodec) marshal( math.MaxInt32, ) } - if time.Now().Before(c.durangoTime) && uint32(numElts) > c.maxSliceLen { - return fmt.Errorf("%w; slice length, %d, exceeds maximum length, %d", - codec.ErrMaxSliceLenExceeded, - numElts, - c.maxSliceLen, - ) - } p.PackInt(uint32(numElts)) // pack # elements if p.Err != nil { return p.Err @@ -445,13 +433,6 @@ func (c *genericCodec) marshal( math.MaxInt32, ) } - if time.Now().Before(c.durangoTime) && uint32(numElts) > c.maxSliceLen { - return fmt.Errorf("%w; map length, %d, exceeds maximum length, %d", - codec.ErrMaxSliceLenExceeded, - numElts, - c.maxSliceLen, - ) - } p.PackInt(uint32(numElts)) // pack # elements if p.Err != nil { return p.Err @@ -619,13 +600,6 @@ func (c *genericCodec) unmarshal( math.MaxInt32, ) } - if time.Now().Before(c.durangoTime) && numElts32 > c.maxSliceLen { - return fmt.Errorf("%w; array length, %d, exceeds maximum length, %d", - codec.ErrMaxSliceLenExceeded, - numElts32, - c.maxSliceLen, - ) - } numElts := int(numElts32) sliceType := value.Type() @@ -732,13 +706,6 @@ func (c *genericCodec) unmarshal( math.MaxInt32, ) } - if time.Now().Before(c.durangoTime) && numElts32 > c.maxSliceLen { - return fmt.Errorf("%w; map length, %d, exceeds maximum length, %d", - codec.ErrMaxSliceLenExceeded, - numElts32, - c.maxSliceLen, - ) - } var ( numElts = int(numElts32) diff --git a/codec/test_codec.go b/codec/test_codec.go index 04d2b53abd38..2dc8b3e2add9 100644 --- a/codec/test_codec.go +++ b/codec/test_codec.go @@ -8,8 +8,6 @@ import ( "testing" "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/utils/wrappers" ) var ( @@ -46,20 +44,12 @@ var ( TestExtraSpace, TestSliceLengthOverflow, TestMap, + TestCanMarshalLargeSlices, } MultipleTagsTests = []func(c GeneralCodec, t testing.TB){ TestMultipleTags, } - - EnforceSliceLenTests = []func(c GeneralCodec, t testing.TB){ - TestCanNotMarshalLargeSlices, - TestCanNotUnmarshalLargeSlices, - } - - IgnoreSliceLenTests = []func(c GeneralCodec, t testing.TB){ - TestCanMarshalLargeSlices, - } ) // The below structs and interfaces exist @@ -1088,35 +1078,6 @@ func TestMap(codec GeneralCodec, t testing.TB) { require.Len(outerArrayBytes, outerArraySize) } -func TestCanNotMarshalLargeSlices(codec GeneralCodec, t testing.TB) { - require := require.New(t) - - data := make([]uint16, 1_000_000) - - manager := NewManager(math.MaxInt) - require.NoError(manager.RegisterCodec(0, codec)) - - _, err := manager.Marshal(0, data) - require.ErrorIs(err, ErrMaxSliceLenExceeded) -} - -func TestCanNotUnmarshalLargeSlices(codec GeneralCodec, t testing.TB) { - require := require.New(t) - - writer := wrappers.Packer{ - Bytes: make([]byte, 2+4+2_000_000), - } - writer.PackShort(0) - writer.PackInt(1_000_000) - - manager := NewManager(math.MaxInt) - require.NoError(manager.RegisterCodec(0, codec)) - - var data []uint16 - _, err := manager.Unmarshal(writer.Bytes, &data) - require.ErrorIs(err, ErrMaxSliceLenExceeded) -} - func TestCanMarshalLargeSlices(codec GeneralCodec, t testing.TB) { require := require.New(t) diff --git a/database/encdb/codec.go b/database/encdb/codec.go index 62223b4fdd2f..b786bec66916 100644 --- a/database/encdb/codec.go +++ b/database/encdb/codec.go @@ -4,8 +4,6 @@ package encdb import ( - "time" - "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" ) @@ -15,7 +13,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewDefaultManager() if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { diff --git a/database/linkeddb/codec.go b/database/linkeddb/codec.go index f1982e1c7cfd..63516a8480c7 100644 --- a/database/linkeddb/codec.go +++ b/database/linkeddb/codec.go @@ -5,7 +5,6 @@ package linkeddb import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -16,7 +15,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewManager(math.MaxInt32) if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { diff --git a/genesis/genesis.go b/genesis/genesis.go index 6a61b80aa559..e25088a59a12 100644 --- a/genesis/genesis.go +++ b/genesis/genesis.go @@ -553,7 +553,6 @@ func VMGenesis(genesisBytes []byte, vmID ids.ID) (*pchaintxs.Tx, error) { func AVAXAssetID(avmGenesisBytes []byte) (ids.ID, error) { parser, err := xchaintxs.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/go.mod b/go.mod index a8df80e7267e..72f0a63b5cfb 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ go 1.21 require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 - github.com/ava-labs/coreth v0.13.1-rc.5 + github.com/ava-labs/coreth v0.13.2-rc.0 github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 diff --git a/go.sum b/go.sum index 4d4df617e114..8a71d2d69073 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/ava-labs/coreth v0.13.1-rc.5 h1:YcTs9nryZLkf4gPmMyFx1TREFpDTPdg/VCNGGHSF2TY= -github.com/ava-labs/coreth v0.13.1-rc.5/go.mod h1:4y1igTe/sFOIrpAtXoY+AdmfftNHrmrhBBRVfGCAPcw= +github.com/ava-labs/coreth v0.13.2-rc.0 h1:D1BqbxAMuMmagueDYOzET8PS1qZxbqnvRhP5eIZ1On8= +github.com/ava-labs/coreth v0.13.2-rc.0/go.mod h1:Mpdw41yvGdb8IJOIpcPZYz5O3wyprVwHPV02J8JvdeA= github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34 h1:mg9Uw6oZFJKytJxgxnl3uxZOs/SB8CVHg6Io4Tf99Zc= github.com/ava-labs/ledger-avalanche/go v0.0.0-20231102202641-ae2ebdaeac34/go.mod h1:pJxaT9bUgeRNVmNRgtCHb7sFDIRKy7CzTQVi8gGNT6g= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= diff --git a/indexer/codec.go b/indexer/codec.go index afde47502ac3..795a59461914 100644 --- a/indexer/codec.go +++ b/indexer/codec.go @@ -5,7 +5,6 @@ package indexer import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -16,7 +15,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewManager(math.MaxInt) if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { diff --git a/node/node.go b/node/node.go index e214e2165d20..48f4fa74457e 100644 --- a/node/node.go +++ b/node/node.go @@ -74,9 +74,7 @@ import ( "github.com/ava-labs/avalanchego/vms" "github.com/ava-labs/avalanchego/vms/avm" "github.com/ava-labs/avalanchego/vms/platformvm" - "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/signer" - "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/registry" "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" @@ -1123,17 +1121,6 @@ func (n *Node) initVMs() error { vdrs = validators.NewManager() } - durangoTime := version.GetDurangoTime(n.Config.NetworkID) - if err := txs.InitCodec(durangoTime); err != nil { - return err - } - if err := block.InitCodec(durangoTime); err != nil { - return err - } - if err := coreth.InitCodec(durangoTime); err != nil { - return err - } - // Register the VMs that Avalanche supports err := utils.Err( n.VMManager.RegisterFactory(context.TODO(), constants.PlatformVMID, &platformvm.Factory{ @@ -1165,7 +1152,7 @@ func (n *Node) initVMs() error { ApricotPhase5Time: version.GetApricotPhase5Time(n.Config.NetworkID), BanffTime: version.GetBanffTime(n.Config.NetworkID), CortinaTime: version.GetCortinaTime(n.Config.NetworkID), - DurangoTime: durangoTime, + DurangoTime: version.GetDurangoTime(n.Config.NetworkID), UseCurrentHeight: n.Config.UseCurrentHeight, }, }), @@ -1173,7 +1160,6 @@ func (n *Node) initVMs() error { Config: avmconfig.Config{ TxFee: n.Config.TxFee, CreateAssetTxFee: n.Config.CreateAssetTxFee, - DurangoTime: durangoTime, }, }), n.VMManager.RegisterFactory(context.TODO(), constants.EVMID, &coreth.Factory{}), diff --git a/snow/engine/avalanche/vertex/codec.go b/snow/engine/avalanche/vertex/codec.go index 12f387d0d25d..3a55f443467e 100644 --- a/snow/engine/avalanche/vertex/codec.go +++ b/snow/engine/avalanche/vertex/codec.go @@ -4,8 +4,6 @@ package vertex import ( - "time" - "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/codec/reflectcodec" @@ -24,8 +22,8 @@ const ( var Codec codec.Manager func init() { - lc0 := linearcodec.New(time.Time{}, []string{reflectcodec.DefaultTagName + "V0"}, maxSize) - lc1 := linearcodec.New(time.Time{}, []string{reflectcodec.DefaultTagName + "V1"}, maxSize) + lc0 := linearcodec.New([]string{reflectcodec.DefaultTagName + "V0"}) + lc1 := linearcodec.New([]string{reflectcodec.DefaultTagName + "V1"}) Codec = codec.NewManager(maxSize) err := utils.Err( diff --git a/vms/avm/block/block_test.go b/vms/avm/block/block_test.go index 6100f1d6d987..37f0e5f5e54b 100644 --- a/vms/avm/block/block_test.go +++ b/vms/avm/block/block_test.go @@ -29,7 +29,6 @@ func TestInvalidBlock(t *testing.T) { require := require.New(t) parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, @@ -45,7 +44,6 @@ func TestStandardBlocks(t *testing.T) { require := require.New(t) parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/block/builder/builder_test.go b/vms/avm/block/builder/builder_test.go index d28507671cf6..89f043844b54 100644 --- a/vms/avm/block/builder/builder_test.go +++ b/vms/avm/block/builder/builder_test.go @@ -513,7 +513,6 @@ func TestBlockBuilderAddLocalTx(t *testing.T) { require.True(ok) parser, err := block.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/block/parser.go b/vms/avm/block/parser.go index f0c359a513b0..bfae841093d1 100644 --- a/vms/avm/block/parser.go +++ b/vms/avm/block/parser.go @@ -5,7 +5,6 @@ package block import ( "reflect" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/utils" @@ -31,8 +30,8 @@ type parser struct { txs.Parser } -func NewParser(durangoTime time.Time, fxs []fxs.Fx) (Parser, error) { - p, err := txs.NewParser(durangoTime, fxs) +func NewParser(fxs []fxs.Fx) (Parser, error) { + p, err := txs.NewParser(fxs) if err != nil { return nil, err } @@ -49,13 +48,12 @@ func NewParser(durangoTime time.Time, fxs []fxs.Fx) (Parser, error) { } func NewCustomParser( - durangoTime time.Time, typeToFxIndex map[reflect.Type]int, clock *mockable.Clock, log logging.Logger, fxs []fxs.Fx, ) (Parser, error) { - p, err := txs.NewCustomParser(durangoTime, typeToFxIndex, clock, log, fxs) + p, err := txs.NewCustomParser(typeToFxIndex, clock, log, fxs) if err != nil { return nil, err } diff --git a/vms/avm/config/config.go b/vms/avm/config/config.go index df6e4f7de2ae..08f6ab04240a 100644 --- a/vms/avm/config/config.go +++ b/vms/avm/config/config.go @@ -3,8 +3,6 @@ package config -import "time" - // Struct collecting all the foundational parameters of the AVM type Config struct { // Fee that is burned by every non-asset creating transaction @@ -12,7 +10,4 @@ type Config struct { // Fee that must be burned by every asset creating transaction CreateAssetTxFee uint64 - - // Time of the Durango network upgrade - DurangoTime time.Time } diff --git a/vms/avm/environment_test.go b/vms/avm/environment_test.go index 92675ef96dea..9c4e5eb6a6f0 100644 --- a/vms/avm/environment_test.go +++ b/vms/avm/environment_test.go @@ -8,7 +8,6 @@ import ( "encoding/json" "math/rand" "testing" - "time" "github.com/stretchr/testify/require" @@ -229,7 +228,6 @@ func getCreateTxFromGenesisTest(tb testing.TB, genesisBytes []byte, assetName st require := require.New(tb) parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/network/gossip_test.go b/vms/avm/network/gossip_test.go index afd08920f1c1..e84f259cbe37 100644 --- a/vms/avm/network/gossip_test.go +++ b/vms/avm/network/gossip_test.go @@ -5,7 +5,6 @@ package network import ( "testing" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" @@ -34,7 +33,6 @@ func TestMarshaller(t *testing.T) { require := require.New(t) parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, @@ -65,7 +63,7 @@ func TestGossipMempoolAdd(t *testing.T) { baseMempool, err := mempool.New("", metrics, toEngine) require.NoError(err) - parser, err := txs.NewParser(time.Time{}, nil) + parser, err := txs.NewParser(nil) require.NoError(err) mempool, err := newGossipMempool( @@ -102,7 +100,7 @@ func TestGossipMempoolAddVerified(t *testing.T) { baseMempool, err := mempool.New("", metrics, toEngine) require.NoError(err) - parser, err := txs.NewParser(time.Time{}, nil) + parser, err := txs.NewParser(nil) require.NoError(err) mempool, err := newGossipMempool( diff --git a/vms/avm/network/network_test.go b/vms/avm/network/network_test.go index f6ce4d9b2ba6..9b55a42aaa74 100644 --- a/vms/avm/network/network_test.go +++ b/vms/avm/network/network_test.go @@ -143,7 +143,6 @@ func TestNetworkIssueTxFromRPC(t *testing.T) { ctrl := gomock.NewController(t) parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, &nftfx.Fx{}, @@ -239,7 +238,6 @@ func TestNetworkIssueTxFromRPCWithoutVerification(t *testing.T) { ctrl := gomock.NewController(t) parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, &nftfx.Fx{}, diff --git a/vms/avm/state/state_test.go b/vms/avm/state/state_test.go index 3657da0e3b2f..a6170c62c405 100644 --- a/vms/avm/state/state_test.go +++ b/vms/avm/state/state_test.go @@ -38,7 +38,6 @@ var ( func init() { var err error parser, err = block.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/static_service.go b/vms/avm/static_service.go index 31a7a5885a62..35a3554ef1d6 100644 --- a/vms/avm/static_service.go +++ b/vms/avm/static_service.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "net/http" - "time" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils" @@ -79,7 +78,6 @@ type BuildGenesisReply struct { // referenced in the UTXO. func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, reply *BuildGenesisReply) error { parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, &nftfx.Fx{}, diff --git a/vms/avm/txs/base_tx_test.go b/vms/avm/txs/base_tx_test.go index 5fb40642433a..5454554ba3d8 100644 --- a/vms/avm/txs/base_tx_test.go +++ b/vms/avm/txs/base_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -127,7 +126,6 @@ func TestBaseTxSerialization(t *testing.T) { }}} parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/txs/create_asset_tx_test.go b/vms/avm/txs/create_asset_tx_test.go index 9ef548eedea2..83e6c99914fe 100644 --- a/vms/avm/txs/create_asset_tx_test.go +++ b/vms/avm/txs/create_asset_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -195,7 +194,6 @@ func TestCreateAssetTxSerialization(t *testing.T) { }} parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, @@ -367,7 +365,6 @@ func TestCreateAssetTxSerializationAgain(t *testing.T) { } parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/txs/executor/executor_test.go b/vms/avm/txs/executor/executor_test.go index d110e4a24a59..6be98183c1ca 100644 --- a/vms/avm/txs/executor/executor_test.go +++ b/vms/avm/txs/executor/executor_test.go @@ -5,7 +5,6 @@ package executor import ( "testing" - "time" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/require" @@ -38,7 +37,6 @@ func TestBaseTxExecutor(t *testing.T) { secpFx := &secp256k1fx.Fx{} parser, err := block.NewParser( - time.Time{}, []fxs.Fx{secpFx}, ) require.NoError(err) @@ -146,7 +144,6 @@ func TestCreateAssetTxExecutor(t *testing.T) { secpFx := &secp256k1fx.Fx{} parser, err := block.NewParser( - time.Time{}, []fxs.Fx{secpFx}, ) require.NoError(err) @@ -292,7 +289,6 @@ func TestOperationTxExecutor(t *testing.T) { secpFx := &secp256k1fx.Fx{} parser, err := block.NewParser( - time.Time{}, []fxs.Fx{secpFx}, ) require.NoError(err) diff --git a/vms/avm/txs/executor/semantic_verifier_test.go b/vms/avm/txs/executor/semantic_verifier_test.go index 5187dd9a38ad..db89e1e5a5e9 100644 --- a/vms/avm/txs/executor/semantic_verifier_test.go +++ b/vms/avm/txs/executor/semantic_verifier_test.go @@ -6,7 +6,6 @@ package executor import ( "reflect" "testing" - "time" "github.com/stretchr/testify/require" "go.uber.org/mock/gomock" @@ -36,7 +35,6 @@ func TestSemanticVerifierBaseTx(t *testing.T) { typeToFxIndex := make(map[reflect.Type]int) secpFx := &secp256k1fx.Fx{} parser, err := txs.NewCustomParser( - time.Time{}, typeToFxIndex, new(mockable.Clock), logging.NoWarn{}, @@ -394,7 +392,6 @@ func TestSemanticVerifierExportTx(t *testing.T) { typeToFxIndex := make(map[reflect.Type]int) secpFx := &secp256k1fx.Fx{} parser, err := txs.NewCustomParser( - time.Time{}, typeToFxIndex, new(mockable.Clock), logging.NoWarn{}, @@ -763,7 +760,6 @@ func TestSemanticVerifierExportTxDifferentSubnet(t *testing.T) { typeToFxIndex := make(map[reflect.Type]int) secpFx := &secp256k1fx.Fx{} parser, err := txs.NewCustomParser( - time.Time{}, typeToFxIndex, new(mockable.Clock), logging.NoWarn{}, @@ -880,7 +876,6 @@ func TestSemanticVerifierImportTx(t *testing.T) { typeToFxIndex := make(map[reflect.Type]int) fx := &secp256k1fx.Fx{} parser, err := txs.NewCustomParser( - time.Time{}, typeToFxIndex, new(mockable.Clock), logging.NoWarn{}, diff --git a/vms/avm/txs/executor/syntactic_verifier_test.go b/vms/avm/txs/executor/syntactic_verifier_test.go index 108ac9e94a60..8726e45477db 100644 --- a/vms/avm/txs/executor/syntactic_verifier_test.go +++ b/vms/avm/txs/executor/syntactic_verifier_test.go @@ -7,7 +7,6 @@ import ( "math" "strings" "testing" - "time" "github.com/stretchr/testify/require" @@ -38,7 +37,6 @@ func TestSyntacticVerifierBaseTx(t *testing.T) { fx := &secp256k1fx.Fx{} parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ fx, }, @@ -411,7 +409,6 @@ func TestSyntacticVerifierCreateAssetTx(t *testing.T) { fx := &secp256k1fx.Fx{} parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ fx, }, @@ -1021,7 +1018,6 @@ func TestSyntacticVerifierOperationTx(t *testing.T) { fx := &secp256k1fx.Fx{} parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ fx, }, @@ -1511,7 +1507,6 @@ func TestSyntacticVerifierImportTx(t *testing.T) { fx := &secp256k1fx.Fx{} parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ fx, }, @@ -1912,7 +1907,6 @@ func TestSyntacticVerifierExportTx(t *testing.T) { fx := &secp256k1fx.Fx{} parser, err := txs.NewParser( - time.Time{}, []fxs.Fx{ fx, }, diff --git a/vms/avm/txs/export_tx_test.go b/vms/avm/txs/export_tx_test.go index 0b714a911fa0..d7c71f6bd632 100644 --- a/vms/avm/txs/export_tx_test.go +++ b/vms/avm/txs/export_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -110,7 +109,6 @@ func TestExportTxSerialization(t *testing.T) { }} parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/txs/import_tx_test.go b/vms/avm/txs/import_tx_test.go index 1f2bbe0ea341..b0cdd8198a5b 100644 --- a/vms/avm/txs/import_tx_test.go +++ b/vms/avm/txs/import_tx_test.go @@ -5,7 +5,6 @@ package txs import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -110,7 +109,6 @@ func TestImportTxSerialization(t *testing.T) { }} parser, err := NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, }, diff --git a/vms/avm/txs/initial_state_test.go b/vms/avm/txs/initial_state_test.go index 5f61deb3e7c6..48c15ae196c4 100644 --- a/vms/avm/txs/initial_state_test.go +++ b/vms/avm/txs/initial_state_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "testing" - "time" "github.com/stretchr/testify/require" @@ -24,7 +23,7 @@ var errTest = errors.New("non-nil error") func TestInitialStateVerifySerialization(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&secp256k1fx.TransferOutput{})) m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(CodecVersion, c)) @@ -81,7 +80,7 @@ func TestInitialStateVerifySerialization(t *testing.T) { func TestInitialStateVerifyNil(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(CodecVersion, c)) numFxs := 1 @@ -94,7 +93,7 @@ func TestInitialStateVerifyNil(t *testing.T) { func TestInitialStateVerifyUnknownFxID(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(CodecVersion, c)) numFxs := 1 @@ -109,7 +108,7 @@ func TestInitialStateVerifyUnknownFxID(t *testing.T) { func TestInitialStateVerifyNilOutput(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(CodecVersion, c)) numFxs := 1 @@ -125,7 +124,7 @@ func TestInitialStateVerifyNilOutput(t *testing.T) { func TestInitialStateVerifyInvalidOutput(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&avax.TestState{})) m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(CodecVersion, c)) @@ -142,7 +141,7 @@ func TestInitialStateVerifyInvalidOutput(t *testing.T) { func TestInitialStateVerifyUnsortedOutputs(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&avax.TestTransferable{})) m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(CodecVersion, c)) diff --git a/vms/avm/txs/operation_test.go b/vms/avm/txs/operation_test.go index 3ca4676eb370..ac9cf62530c6 100644 --- a/vms/avm/txs/operation_test.go +++ b/vms/avm/txs/operation_test.go @@ -5,7 +5,6 @@ package txs import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -80,7 +79,7 @@ func TestOperationVerify(t *testing.T) { func TestOperationSorting(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&testOperable{})) m := codec.NewDefaultManager() diff --git a/vms/avm/txs/parser.go b/vms/avm/txs/parser.go index 979c71d8a7c8..c5b7fe19edc0 100644 --- a/vms/avm/txs/parser.go +++ b/vms/avm/txs/parser.go @@ -7,7 +7,6 @@ import ( "fmt" "math" "reflect" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -40,9 +39,8 @@ type parser struct { gc linearcodec.Codec } -func NewParser(durangoTime time.Time, fxs []fxs.Fx) (Parser, error) { +func NewParser(fxs []fxs.Fx) (Parser, error) { return NewCustomParser( - durangoTime, make(map[reflect.Type]int), &mockable.Clock{}, logging.NoLog{}, @@ -51,14 +49,13 @@ func NewParser(durangoTime time.Time, fxs []fxs.Fx) (Parser, error) { } func NewCustomParser( - durangoTime time.Time, typeToFxIndex map[reflect.Type]int, clock *mockable.Clock, log logging.Logger, fxs []fxs.Fx, ) (Parser, error) { - gc := linearcodec.NewDefault(time.Time{}) - c := linearcodec.NewDefault(durangoTime) + gc := linearcodec.NewDefault() + c := linearcodec.NewDefault() gcm := codec.NewManager(math.MaxInt32) cm := codec.NewDefaultManager() diff --git a/vms/avm/vm.go b/vms/avm/vm.go index 718f7d069d3d..fe302f97cf28 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -217,7 +217,6 @@ func (vm *VM) Initialize( vm.typeToFxIndex = map[reflect.Type]int{} vm.parser, err = block.NewCustomParser( - vm.DurangoTime, vm.typeToFxIndex, &vm.clock, ctx.Log, diff --git a/vms/components/avax/asset_test.go b/vms/components/avax/asset_test.go index ad7628ce98b9..ccb6f5549630 100644 --- a/vms/components/avax/asset_test.go +++ b/vms/components/avax/asset_test.go @@ -5,7 +5,6 @@ package avax import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -29,7 +28,7 @@ func TestAssetVerifyEmpty(t *testing.T) { func TestAssetID(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() manager := codec.NewDefaultManager() require.NoError(manager.RegisterCodec(codecVersion, c)) diff --git a/vms/components/avax/transferables_test.go b/vms/components/avax/transferables_test.go index 755a0124eb7b..f46d580e839a 100644 --- a/vms/components/avax/transferables_test.go +++ b/vms/components/avax/transferables_test.go @@ -5,7 +5,6 @@ package avax import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -43,7 +42,7 @@ func TestTransferableOutputVerify(t *testing.T) { func TestTransferableOutputSorting(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&TestTransferable{})) manager := codec.NewDefaultManager() require.NoError(manager.RegisterCodec(codecVersion, c)) @@ -85,7 +84,7 @@ func TestTransferableOutputSorting(t *testing.T) { func TestTransferableOutputSerialization(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&secp256k1fx.TransferOutput{})) manager := codec.NewDefaultManager() require.NoError(manager.RegisterCodec(codecVersion, c)) @@ -176,7 +175,7 @@ func TestTransferableInputVerify(t *testing.T) { func TestTransferableInputSorting(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&TestTransferable{})) ins := []*TransferableInput{ @@ -233,7 +232,7 @@ func TestTransferableInputSorting(t *testing.T) { func TestTransferableInputSerialization(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() require.NoError(c.RegisterType(&secp256k1fx.TransferInput{})) manager := codec.NewDefaultManager() require.NoError(manager.RegisterCodec(codecVersion, c)) diff --git a/vms/components/avax/utxo_fetching_test.go b/vms/components/avax/utxo_fetching_test.go index e36545c19cb7..25fe3fd91155 100644 --- a/vms/components/avax/utxo_fetching_test.go +++ b/vms/components/avax/utxo_fetching_test.go @@ -5,7 +5,6 @@ package avax import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -40,7 +39,7 @@ func TestFetchUTXOs(t *testing.T) { }, } - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() manager := codec.NewDefaultManager() require.NoError(c.RegisterType(&secp256k1fx.TransferOutput{})) @@ -73,7 +72,7 @@ func TestGetPaginatedUTXOs(t *testing.T) { addr2 := ids.GenerateTestShortID() addrs := set.Of(addr0, addr1) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() manager := codec.NewDefaultManager() require.NoError(c.RegisterType(&secp256k1fx.TransferOutput{})) diff --git a/vms/components/avax/utxo_id_test.go b/vms/components/avax/utxo_id_test.go index fed21d5ce986..09887c0312e9 100644 --- a/vms/components/avax/utxo_id_test.go +++ b/vms/components/avax/utxo_id_test.go @@ -6,7 +6,6 @@ package avax import ( "math" "testing" - "time" "github.com/stretchr/testify/require" @@ -24,7 +23,7 @@ func TestUTXOIDVerifyNil(t *testing.T) { func TestUTXOID(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() manager := codec.NewDefaultManager() require.NoError(manager.RegisterCodec(codecVersion, c)) diff --git a/vms/components/avax/utxo_state_test.go b/vms/components/avax/utxo_state_test.go index fa4c530e011a..09213bfa1bc6 100644 --- a/vms/components/avax/utxo_state_test.go +++ b/vms/components/avax/utxo_state_test.go @@ -5,7 +5,6 @@ package avax import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -42,7 +41,7 @@ func TestUTXOState(t *testing.T) { } utxoID := utxo.InputID() - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() manager := codec.NewDefaultManager() require.NoError(c.RegisterType(&secp256k1fx.MintOutput{})) diff --git a/vms/components/avax/utxo_test.go b/vms/components/avax/utxo_test.go index a79c8fcb6cd6..54f8360173a7 100644 --- a/vms/components/avax/utxo_test.go +++ b/vms/components/avax/utxo_test.go @@ -5,7 +5,6 @@ package avax import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -33,7 +32,7 @@ func TestUTXOVerifyEmpty(t *testing.T) { func TestUTXOSerialize(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() manager := codec.NewDefaultManager() require.NoError(c.RegisterType(&secp256k1fx.MintOutput{})) diff --git a/vms/components/keystore/codec.go b/vms/components/keystore/codec.go index 15576b73e4ea..4e5a01db6dd0 100644 --- a/vms/components/keystore/codec.go +++ b/vms/components/keystore/codec.go @@ -5,7 +5,6 @@ package keystore import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -20,9 +19,9 @@ var ( ) func init() { - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() Codec = codec.NewDefaultManager() - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() LegacyCodec = codec.NewManager(math.MaxInt32) err := utils.Err( diff --git a/vms/example/xsvm/tx/codec.go b/vms/example/xsvm/tx/codec.go index f61c7bf18098..4ba775abb3f4 100644 --- a/vms/example/xsvm/tx/codec.go +++ b/vms/example/xsvm/tx/codec.go @@ -5,7 +5,6 @@ package tx import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -17,7 +16,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() Codec = codec.NewManager(math.MaxInt32) err := utils.Err( diff --git a/vms/nftfx/fx_test.go b/vms/nftfx/fx_test.go index 1ed3426f5b11..99a047b11328 100644 --- a/vms/nftfx/fx_test.go +++ b/vms/nftfx/fx_test.go @@ -39,7 +39,7 @@ var ( func TestFxInitialize(t *testing.T) { vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } fx := Fx{} @@ -56,7 +56,7 @@ func TestFxVerifyMintOperation(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -92,7 +92,7 @@ func TestFxVerifyMintOperationWrongTx(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -126,7 +126,7 @@ func TestFxVerifyMintOperationWrongNumberUTXOs(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -157,7 +157,7 @@ func TestFxVerifyMintOperationWrongCredential(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -189,7 +189,7 @@ func TestFxVerifyMintOperationInvalidUTXO(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -220,7 +220,7 @@ func TestFxVerifyMintOperationFailingVerification(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -258,7 +258,7 @@ func TestFxVerifyMintOperationInvalidGroupID(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -296,7 +296,7 @@ func TestFxVerifyTransferOperation(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -346,7 +346,7 @@ func TestFxVerifyTransferOperationWrongUTXO(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -387,7 +387,7 @@ func TestFxVerifyTransferOperationFailedVerify(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -435,7 +435,7 @@ func TestFxVerifyTransferOperationWrongGroupID(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -486,7 +486,7 @@ func TestFxVerifyTransferOperationWrongBytes(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -537,7 +537,7 @@ func TestFxVerifyTransferOperationTooSoon(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -589,7 +589,7 @@ func TestFxVerifyOperationUnknownOperation(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -625,7 +625,7 @@ func TestFxVerifyTransfer(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 4fdf634a190f..6c1471a8b2de 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -387,7 +387,7 @@ func defaultFx(t *testing.T, clk *mockable.Clock, log logging.Logger, isBootstra require := require.New(t) fxVMInt := &fxVMInt{ - registry: linearcodec.NewDefault(time.Time{}), + registry: linearcodec.NewDefault(), clk: clk, log: log, } diff --git a/vms/platformvm/block/codec.go b/vms/platformvm/block/codec.go index 33babbaf3a79..f0f66a414811 100644 --- a/vms/platformvm/block/codec.go +++ b/vms/platformvm/block/codec.go @@ -5,7 +5,6 @@ package block import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -26,13 +25,9 @@ var ( Codec codec.Manager ) -// TODO: Remove after v1.11.x has activated -// -// Invariant: InitCodec, Codec, and GenesisCodec must not be accessed -// concurrently -func InitCodec(durangoTime time.Time) error { - c := linearcodec.NewDefault(durangoTime) - gc := linearcodec.NewDefault(time.Time{}) +func init() { + c := linearcodec.NewDefault() + gc := linearcodec.NewDefault() errs := wrappers.Errs{} for _, c := range []linearcodec.Codec{c, gc} { @@ -44,24 +39,14 @@ func InitCodec(durangoTime time.Time) error { ) } - newCodec := codec.NewDefaultManager() - newGenesisCodec := codec.NewManager(math.MaxInt32) + Codec = codec.NewDefaultManager() + GenesisCodec = codec.NewManager(math.MaxInt32) errs.Add( - newCodec.RegisterCodec(CodecVersion, c), - newGenesisCodec.RegisterCodec(CodecVersion, gc), + Codec.RegisterCodec(CodecVersion, c), + GenesisCodec.RegisterCodec(CodecVersion, gc), ) if errs.Errored() { - return errs.Err - } - - Codec = newCodec - GenesisCodec = newGenesisCodec - return nil -} - -func init() { - if err := InitCodec(time.Time{}); err != nil { - panic(err) + panic(errs.Err) } } diff --git a/vms/platformvm/block/executor/helpers_test.go b/vms/platformvm/block/executor/helpers_test.go index 825625b7c77e..4f016808f3d4 100644 --- a/vms/platformvm/block/executor/helpers_test.go +++ b/vms/platformvm/block/executor/helpers_test.go @@ -408,7 +408,7 @@ func (fvi *fxVMInt) Logger() logging.Logger { func defaultFx(clk *mockable.Clock, log logging.Logger, isBootstrapped bool) fx.Fx { fxVMInt := &fxVMInt{ - registry: linearcodec.NewDefault(time.Time{}), + registry: linearcodec.NewDefault(), clk: clk, log: log, } diff --git a/vms/platformvm/state/metadata_codec.go b/vms/platformvm/state/metadata_codec.go index 65832ed77460..f2f5478a89d3 100644 --- a/vms/platformvm/state/metadata_codec.go +++ b/vms/platformvm/state/metadata_codec.go @@ -5,7 +5,6 @@ package state import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -23,8 +22,8 @@ const ( var MetadataCodec codec.Manager func init() { - c0 := linearcodec.New(time.Time{}, []string{CodecVersion0Tag}, math.MaxInt32) - c1 := linearcodec.New(time.Time{}, []string{CodecVersion0Tag, CodecVersion1Tag}, math.MaxInt32) + c0 := linearcodec.New([]string{CodecVersion0Tag}) + c1 := linearcodec.New([]string{CodecVersion0Tag, CodecVersion1Tag}) MetadataCodec = codec.NewManager(math.MaxInt32) err := utils.Err( diff --git a/vms/platformvm/txs/codec.go b/vms/platformvm/txs/codec.go index 36fe2e5a8eb0..a93477af7074 100644 --- a/vms/platformvm/txs/codec.go +++ b/vms/platformvm/txs/codec.go @@ -5,7 +5,6 @@ package txs import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -28,13 +27,9 @@ var ( GenesisCodec codec.Manager ) -// TODO: Remove after v1.11.x has activated -// -// Invariant: InitCodec, Codec, and GenesisCodec must not be accessed -// concurrently -func InitCodec(durangoTime time.Time) error { - c := linearcodec.NewDefault(durangoTime) - gc := linearcodec.NewDefault(time.Time{}) +func init() { + c := linearcodec.NewDefault() + gc := linearcodec.NewDefault() errs := wrappers.Errs{} for _, c := range []linearcodec.Codec{c, gc} { @@ -50,24 +45,14 @@ func InitCodec(durangoTime time.Time) error { errs.Add(RegisterDUnsignedTxsTypes(c)) } - newCodec := codec.NewDefaultManager() - newGenesisCodec := codec.NewManager(math.MaxInt32) + Codec = codec.NewDefaultManager() + GenesisCodec = codec.NewManager(math.MaxInt32) errs.Add( - newCodec.RegisterCodec(CodecVersion, c), - newGenesisCodec.RegisterCodec(CodecVersion, gc), + Codec.RegisterCodec(CodecVersion, c), + GenesisCodec.RegisterCodec(CodecVersion, gc), ) if errs.Errored() { - return errs.Err - } - - Codec = newCodec - GenesisCodec = newGenesisCodec - return nil -} - -func init() { - if err := InitCodec(time.Time{}); err != nil { - panic(err) + panic(errs.Err) } } diff --git a/vms/platformvm/txs/executor/helpers_test.go b/vms/platformvm/txs/executor/helpers_test.go index f319b19826a2..643060ddbdb3 100644 --- a/vms/platformvm/txs/executor/helpers_test.go +++ b/vms/platformvm/txs/executor/helpers_test.go @@ -364,7 +364,7 @@ func (fvi *fxVMInt) Logger() logging.Logger { func defaultFx(clk *mockable.Clock, log logging.Logger, isBootstrapped bool) fx.Fx { fxVMInt := &fxVMInt{ - registry: linearcodec.NewDefault(time.Time{}), + registry: linearcodec.NewDefault(), clk: clk, log: log, } diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index 4dd1b2d6af38..d985b408be05 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -130,7 +130,7 @@ func (vm *VM) Initialize( vm.db = db // Note: this codec is never used to serialize anything - vm.codecRegistry = linearcodec.NewDefault(time.Time{}) + vm.codecRegistry = linearcodec.NewDefault() vm.fx = &secp256k1fx.Fx{} if err := vm.fx.Initialize(vm); err != nil { return err diff --git a/vms/platformvm/warp/codec.go b/vms/platformvm/warp/codec.go index 6ef6e526bdc1..8d2193827346 100644 --- a/vms/platformvm/warp/codec.go +++ b/vms/platformvm/warp/codec.go @@ -5,7 +5,6 @@ package warp import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -18,7 +17,7 @@ var Codec codec.Manager func init() { Codec = codec.NewManager(math.MaxInt) - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() err := utils.Err( lc.RegisterType(&BitSetSignature{}), diff --git a/vms/platformvm/warp/payload/codec.go b/vms/platformvm/warp/payload/codec.go index d188029abfed..b89db089d454 100644 --- a/vms/platformvm/warp/payload/codec.go +++ b/vms/platformvm/warp/payload/codec.go @@ -4,8 +4,6 @@ package payload import ( - "time" - "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" "github.com/ava-labs/avalanchego/utils" @@ -22,7 +20,7 @@ var Codec codec.Manager func init() { Codec = codec.NewManager(MaxMessageSize) - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() err := utils.Err( lc.RegisterType(&Hash{}), diff --git a/vms/propertyfx/fx_test.go b/vms/propertyfx/fx_test.go index 0cd995ba5282..10a96e6e5b0b 100644 --- a/vms/propertyfx/fx_test.go +++ b/vms/propertyfx/fx_test.go @@ -39,7 +39,7 @@ var ( func TestFxInitialize(t *testing.T) { vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } fx := Fx{} @@ -56,7 +56,7 @@ func TestFxVerifyMintOperation(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -98,7 +98,7 @@ func TestFxVerifyMintOperationWrongTx(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -132,7 +132,7 @@ func TestFxVerifyMintOperationWrongNumberUTXOs(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -163,7 +163,7 @@ func TestFxVerifyMintOperationWrongCredential(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -195,7 +195,7 @@ func TestFxVerifyMintOperationInvalidUTXO(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -226,7 +226,7 @@ func TestFxVerifyMintOperationFailingVerification(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -264,7 +264,7 @@ func TestFxVerifyMintOperationInvalidGroupID(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -301,7 +301,7 @@ func TestFxVerifyTransferOperation(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -335,7 +335,7 @@ func TestFxVerifyTransferOperationWrongUTXO(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -364,7 +364,7 @@ func TestFxVerifyTransferOperationFailedVerify(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -399,7 +399,7 @@ func TestFxVerifyOperationUnknownOperation(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -431,7 +431,7 @@ func TestFxVerifyTransfer(t *testing.T) { require := require.New(t) vm := secp256k1fx.TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) diff --git a/vms/proposervm/block/codec.go b/vms/proposervm/block/codec.go index ca2318002093..a00ad7de2506 100644 --- a/vms/proposervm/block/codec.go +++ b/vms/proposervm/block/codec.go @@ -5,7 +5,6 @@ package block import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -17,7 +16,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() // The maximum block size is enforced by the p2p message size limit. // See: [constants.DefaultMaxMessageSize] Codec = codec.NewManager(math.MaxInt) diff --git a/vms/proposervm/state/codec.go b/vms/proposervm/state/codec.go index 63727894e356..d533ed948c8d 100644 --- a/vms/proposervm/state/codec.go +++ b/vms/proposervm/state/codec.go @@ -5,7 +5,6 @@ package state import ( "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -16,7 +15,7 @@ const CodecVersion = 0 var Codec codec.Manager func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewManager(math.MaxInt32) err := Codec.RegisterCodec(CodecVersion, lc) diff --git a/vms/proposervm/summary/codec.go b/vms/proposervm/summary/codec.go index 41a9eb9a37d0..72617101b84c 100644 --- a/vms/proposervm/summary/codec.go +++ b/vms/proposervm/summary/codec.go @@ -6,7 +6,6 @@ package summary import ( "errors" "math" - "time" "github.com/ava-labs/avalanchego/codec" "github.com/ava-labs/avalanchego/codec/linearcodec" @@ -21,7 +20,7 @@ var ( ) func init() { - lc := linearcodec.NewDefault(time.Time{}) + lc := linearcodec.NewDefault() Codec = codec.NewManager(math.MaxInt32) if err := Codec.RegisterCodec(CodecVersion, lc); err != nil { panic(err) diff --git a/vms/secp256k1fx/credential_test.go b/vms/secp256k1fx/credential_test.go index e69b98b286e7..c08548e0bcc7 100644 --- a/vms/secp256k1fx/credential_test.go +++ b/vms/secp256k1fx/credential_test.go @@ -5,7 +5,6 @@ package secp256k1fx import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -28,7 +27,7 @@ func TestCredentialVerifyNil(t *testing.T) { func TestCredentialSerialize(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(0, c)) diff --git a/vms/secp256k1fx/fx_test.go b/vms/secp256k1fx/fx_test.go index dcdf78385404..388d7bc14d84 100644 --- a/vms/secp256k1fx/fx_test.go +++ b/vms/secp256k1fx/fx_test.go @@ -53,7 +53,7 @@ func init() { func TestFxInitialize(t *testing.T) { vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } fx := Fx{} @@ -69,7 +69,7 @@ func TestFxInitializeInvalid(t *testing.T) { func TestFxVerifyTransfer(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -107,7 +107,7 @@ func TestFxVerifyTransfer(t *testing.T) { func TestFxVerifyTransferNilTx(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -143,7 +143,7 @@ func TestFxVerifyTransferNilTx(t *testing.T) { func TestFxVerifyTransferNilOutput(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -170,7 +170,7 @@ func TestFxVerifyTransferNilOutput(t *testing.T) { func TestFxVerifyTransferNilInput(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -201,7 +201,7 @@ func TestFxVerifyTransferNilInput(t *testing.T) { func TestFxVerifyTransferNilCredential(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -233,7 +233,7 @@ func TestFxVerifyTransferNilCredential(t *testing.T) { func TestFxVerifyTransferInvalidOutput(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -270,7 +270,7 @@ func TestFxVerifyTransferInvalidOutput(t *testing.T) { func TestFxVerifyTransferWrongAmounts(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -307,7 +307,7 @@ func TestFxVerifyTransferWrongAmounts(t *testing.T) { func TestFxVerifyTransferTimelocked(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -344,7 +344,7 @@ func TestFxVerifyTransferTimelocked(t *testing.T) { func TestFxVerifyTransferTooManySigners(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -382,7 +382,7 @@ func TestFxVerifyTransferTooManySigners(t *testing.T) { func TestFxVerifyTransferTooFewSigners(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -417,7 +417,7 @@ func TestFxVerifyTransferTooFewSigners(t *testing.T) { func TestFxVerifyTransferMismatchedSigners(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -455,7 +455,7 @@ func TestFxVerifyTransferMismatchedSigners(t *testing.T) { func TestFxVerifyTransferInvalidSignature(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -495,7 +495,7 @@ func TestFxVerifyTransferInvalidSignature(t *testing.T) { func TestFxVerifyTransferWrongSigner(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -535,7 +535,7 @@ func TestFxVerifyTransferWrongSigner(t *testing.T) { func TestFxVerifyTransferSigIndexOOB(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -575,7 +575,7 @@ func TestFxVerifyTransferSigIndexOOB(t *testing.T) { func TestFxVerifyOperation(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -627,7 +627,7 @@ func TestFxVerifyOperation(t *testing.T) { func TestFxVerifyOperationUnknownTx(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -679,7 +679,7 @@ func TestFxVerifyOperationUnknownTx(t *testing.T) { func TestFxVerifyOperationUnknownOperation(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -709,7 +709,7 @@ func TestFxVerifyOperationUnknownOperation(t *testing.T) { func TestFxVerifyOperationUnknownCredential(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -757,7 +757,7 @@ func TestFxVerifyOperationUnknownCredential(t *testing.T) { func TestFxVerifyOperationWrongNumberOfUTXOs(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -810,7 +810,7 @@ func TestFxVerifyOperationWrongNumberOfUTXOs(t *testing.T) { func TestFxVerifyOperationUnknownUTXOType(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -855,7 +855,7 @@ func TestFxVerifyOperationUnknownUTXOType(t *testing.T) { func TestFxVerifyOperationInvalidOperationVerify(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -905,7 +905,7 @@ func TestFxVerifyOperationInvalidOperationVerify(t *testing.T) { func TestFxVerifyOperationMismatchedMintOutputs(t *testing.T) { require := require.New(t) vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } date := time.Date(2019, time.January, 19, 16, 25, 17, 3, time.UTC) @@ -952,7 +952,7 @@ func TestFxVerifyOperationMismatchedMintOutputs(t *testing.T) { func TestVerifyPermission(t *testing.T) { vm := TestVM{ - Codec: linearcodec.NewDefault(time.Time{}), + Codec: linearcodec.NewDefault(), Log: logging.NoLog{}, } fx := Fx{} diff --git a/vms/secp256k1fx/transfer_input_test.go b/vms/secp256k1fx/transfer_input_test.go index c155d848e559..4434584e1a9d 100644 --- a/vms/secp256k1fx/transfer_input_test.go +++ b/vms/secp256k1fx/transfer_input_test.go @@ -5,7 +5,6 @@ package secp256k1fx import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -81,7 +80,7 @@ func TestTransferInputVerifyUnsorted(t *testing.T) { func TestTransferInputSerialize(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(0, c)) diff --git a/vms/secp256k1fx/transfer_output_test.go b/vms/secp256k1fx/transfer_output_test.go index 864fb85b9ff0..b1d8a2170b5a 100644 --- a/vms/secp256k1fx/transfer_output_test.go +++ b/vms/secp256k1fx/transfer_output_test.go @@ -5,7 +5,6 @@ package secp256k1fx import ( "testing" - "time" "github.com/stretchr/testify/require" @@ -136,7 +135,7 @@ func TestOutputVerifyDuplicated(t *testing.T) { func TestOutputSerialize(t *testing.T) { require := require.New(t) - c := linearcodec.NewDefault(time.Time{}) + c := linearcodec.NewDefault() m := codec.NewDefaultManager() require.NoError(m.RegisterCodec(0, c)) diff --git a/wallet/chain/x/constants.go b/wallet/chain/x/constants.go index 47efbfc2ff6d..690fa168b5fd 100644 --- a/wallet/chain/x/constants.go +++ b/wallet/chain/x/constants.go @@ -4,8 +4,6 @@ package x import ( - "time" - "github.com/ava-labs/avalanchego/vms/avm/block" "github.com/ava-labs/avalanchego/vms/avm/fxs" "github.com/ava-labs/avalanchego/vms/nftfx" @@ -25,7 +23,6 @@ var Parser block.Parser func init() { var err error Parser, err = block.NewParser( - time.Time{}, []fxs.Fx{ &secp256k1fx.Fx{}, &nftfx.Fx{}, From f3abe3ca760e3579b863316431ec49706ca70ccd Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Mon, 11 Mar 2024 09:37:40 -0400 Subject: [PATCH 3/4] Remove engine type handling for everything other than GetAncestors (#2800) --- message/fields.go | 6 - message/inbound_msg_builder.go | 14 +- message/inbound_msg_builder_test.go | 9 - message/internal_msg_builder.go | 104 +++----- message/messages_test.go | 42 ++-- message/mock_outbound_message_builder.go | 48 ++-- message/outbound_msg_builder.go | 30 +-- network/network_test.go | 5 +- network/peer/peer_test.go | 4 +- proto/p2p/p2p.proto | 17 +- proto/pb/p2p/p2p.pb.go | 231 ++++++------------ snow/engine/avalanche/getter/getter.go | 44 ++-- snow/engine/avalanche/getter/getter_test.go | 108 -------- snow/networking/handler/handler_test.go | 14 +- snow/networking/handler/message_queue_test.go | 16 +- snow/networking/router/chain_router_test.go | 24 +- snow/networking/sender/sender.go | 30 +-- snow/networking/sender/sender_test.go | 28 +-- 18 files changed, 226 insertions(+), 548 deletions(-) delete mode 100644 snow/engine/avalanche/getter/getter_test.go diff --git a/message/fields.go b/message/fields.go index 94dcf2a23061..453315f4323a 100644 --- a/message/fields.go +++ b/message/fields.go @@ -51,13 +51,7 @@ var ( _ requestIDGetter = (*p2p.AppRequest)(nil) _ requestIDGetter = (*p2p.AppResponse)(nil) - _ engineTypeGetter = (*p2p.GetAcceptedFrontier)(nil) - _ engineTypeGetter = (*p2p.GetAccepted)(nil) _ engineTypeGetter = (*p2p.GetAncestors)(nil) - _ engineTypeGetter = (*p2p.Get)(nil) - _ engineTypeGetter = (*p2p.Put)(nil) - _ engineTypeGetter = (*p2p.PushQuery)(nil) - _ engineTypeGetter = (*p2p.PullQuery)(nil) _ deadlineGetter = (*p2p.GetStateSummaryFrontier)(nil) _ deadlineGetter = (*p2p.GetAcceptedStateSummary)(nil) diff --git a/message/inbound_msg_builder.go b/message/inbound_msg_builder.go index b32dbc5d480d..b7b6048d89c8 100644 --- a/message/inbound_msg_builder.go +++ b/message/inbound_msg_builder.go @@ -117,16 +117,14 @@ func InboundGetAcceptedFrontier( requestID uint32, deadline time.Duration, nodeID ids.NodeID, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, op: GetAcceptedFrontierOp, message: &p2p.GetAcceptedFrontier{ - ChainId: chainID[:], - RequestId: requestID, - Deadline: uint64(deadline), - EngineType: engineType, + ChainId: chainID[:], + RequestId: requestID, + Deadline: uint64(deadline), }, expiration: time.Now().Add(deadline), } @@ -156,7 +154,6 @@ func InboundGetAccepted( deadline time.Duration, containerIDs []ids.ID, nodeID ids.NodeID, - engineType p2p.EngineType, ) InboundMessage { containerIDBytes := make([][]byte, len(containerIDs)) encodeIDs(containerIDs, containerIDBytes) @@ -168,7 +165,6 @@ func InboundGetAccepted( RequestId: requestID, Deadline: uint64(deadline), ContainerIds: containerIDBytes, - EngineType: engineType, }, expiration: time.Now().Add(deadline), } @@ -201,7 +197,6 @@ func InboundPushQuery( container []byte, requestedHeight uint64, nodeID ids.NodeID, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, @@ -212,7 +207,6 @@ func InboundPushQuery( Deadline: uint64(deadline), Container: container, RequestedHeight: requestedHeight, - EngineType: engineType, }, expiration: time.Now().Add(deadline), } @@ -225,7 +219,6 @@ func InboundPullQuery( containerID ids.ID, requestedHeight uint64, nodeID ids.NodeID, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, @@ -236,7 +229,6 @@ func InboundPullQuery( Deadline: uint64(deadline), ContainerId: containerID[:], RequestedHeight: requestedHeight, - EngineType: engineType, }, expiration: time.Now().Add(deadline), } diff --git a/message/inbound_msg_builder_test.go b/message/inbound_msg_builder_test.go index 37f713a387bf..09269d1e2ad0 100644 --- a/message/inbound_msg_builder_test.go +++ b/message/inbound_msg_builder_test.go @@ -45,7 +45,6 @@ func TestInboundMsgBuilder(t *testing.T) { acceptedContainerID = ids.GenerateTestID() summaryIDs = []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} heights = []uint64{1000, 2000} - engineType = p2p.EngineType_ENGINE_TYPE_SNOWMAN ) t.Run( @@ -162,7 +161,6 @@ func TestInboundMsgBuilder(t *testing.T) { requestID, deadline, nodeID, - engineType, ) end := time.Now() @@ -174,7 +172,6 @@ func TestInboundMsgBuilder(t *testing.T) { innerMsg := msg.Message().(*p2p.GetAcceptedFrontier) require.Equal(chainID[:], innerMsg.ChainId) require.Equal(requestID, innerMsg.RequestId) - require.Equal(engineType, innerMsg.EngineType) }, ) @@ -213,7 +210,6 @@ func TestInboundMsgBuilder(t *testing.T) { deadline, containerIDs, nodeID, - engineType, ) end := time.Now() @@ -225,7 +221,6 @@ func TestInboundMsgBuilder(t *testing.T) { innerMsg := msg.Message().(*p2p.GetAccepted) require.Equal(chainID[:], innerMsg.ChainId) require.Equal(requestID, innerMsg.RequestId) - require.Equal(engineType, innerMsg.EngineType) }, ) @@ -270,7 +265,6 @@ func TestInboundMsgBuilder(t *testing.T) { container, requestedHeight, nodeID, - engineType, ) end := time.Now() @@ -284,7 +278,6 @@ func TestInboundMsgBuilder(t *testing.T) { require.Equal(requestID, innerMsg.RequestId) require.Equal(container, innerMsg.Container) require.Equal(requestedHeight, innerMsg.RequestedHeight) - require.Equal(engineType, innerMsg.EngineType) }, ) @@ -301,7 +294,6 @@ func TestInboundMsgBuilder(t *testing.T) { containerIDs[0], requestedHeight, nodeID, - engineType, ) end := time.Now() @@ -315,7 +307,6 @@ func TestInboundMsgBuilder(t *testing.T) { require.Equal(requestID, innerMsg.RequestId) require.Equal(containerIDs[0][:], innerMsg.ContainerId) require.Equal(requestedHeight, innerMsg.RequestedHeight) - require.Equal(engineType, innerMsg.EngineType) }, ) diff --git a/message/internal_msg_builder.go b/message/internal_msg_builder.go index 38a95cb78a8c..141dabaae414 100644 --- a/message/internal_msg_builder.go +++ b/message/internal_msg_builder.go @@ -27,30 +27,26 @@ var ( _ chainIDGetter = (*GetAcceptedStateSummaryFailed)(nil) _ requestIDGetter = (*GetAcceptedStateSummaryFailed)(nil) - _ fmt.Stringer = (*GetAcceptedFrontierFailed)(nil) - _ chainIDGetter = (*GetAcceptedFrontierFailed)(nil) - _ requestIDGetter = (*GetAcceptedFrontierFailed)(nil) - _ engineTypeGetter = (*GetAcceptedFrontierFailed)(nil) + _ fmt.Stringer = (*GetAcceptedFrontierFailed)(nil) + _ chainIDGetter = (*GetAcceptedFrontierFailed)(nil) + _ requestIDGetter = (*GetAcceptedFrontierFailed)(nil) - _ fmt.Stringer = (*GetAcceptedFailed)(nil) - _ chainIDGetter = (*GetAcceptedFailed)(nil) - _ requestIDGetter = (*GetAcceptedFailed)(nil) - _ engineTypeGetter = (*GetAcceptedFailed)(nil) + _ fmt.Stringer = (*GetAcceptedFailed)(nil) + _ chainIDGetter = (*GetAcceptedFailed)(nil) + _ requestIDGetter = (*GetAcceptedFailed)(nil) _ fmt.Stringer = (*GetAncestorsFailed)(nil) _ chainIDGetter = (*GetAncestorsFailed)(nil) _ requestIDGetter = (*GetAncestorsFailed)(nil) _ engineTypeGetter = (*GetAncestorsFailed)(nil) - _ fmt.Stringer = (*GetFailed)(nil) - _ chainIDGetter = (*GetFailed)(nil) - _ requestIDGetter = (*GetFailed)(nil) - _ engineTypeGetter = (*GetFailed)(nil) + _ fmt.Stringer = (*GetFailed)(nil) + _ chainIDGetter = (*GetFailed)(nil) + _ requestIDGetter = (*GetFailed)(nil) - _ fmt.Stringer = (*QueryFailed)(nil) - _ chainIDGetter = (*QueryFailed)(nil) - _ requestIDGetter = (*QueryFailed)(nil) - _ engineTypeGetter = (*QueryFailed)(nil) + _ fmt.Stringer = (*QueryFailed)(nil) + _ chainIDGetter = (*QueryFailed)(nil) + _ requestIDGetter = (*QueryFailed)(nil) _ fmt.Stringer = (*CrossChainAppRequest)(nil) _ sourceChainIDGetter = (*CrossChainAppRequest)(nil) @@ -147,15 +143,14 @@ func InternalGetAcceptedStateSummaryFailed( } type GetAcceptedFrontierFailed struct { - ChainID ids.ID `json:"chain_id,omitempty"` - RequestID uint32 `json:"request_id,omitempty"` - EngineType p2p.EngineType `json:"engine_type,omitempty"` + ChainID ids.ID `json:"chain_id,omitempty"` + RequestID uint32 `json:"request_id,omitempty"` } func (m *GetAcceptedFrontierFailed) String() string { return fmt.Sprintf( - "ChainID: %s RequestID: %d EngineType: %s", - m.ChainID, m.RequestID, m.EngineType, + "ChainID: %s RequestID: %d", + m.ChainID, m.RequestID, ) } @@ -167,38 +162,31 @@ func (m *GetAcceptedFrontierFailed) GetRequestId() uint32 { return m.RequestID } -func (m *GetAcceptedFrontierFailed) GetEngineType() p2p.EngineType { - return m.EngineType -} - func InternalGetAcceptedFrontierFailed( nodeID ids.NodeID, chainID ids.ID, requestID uint32, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, op: GetAcceptedFrontierFailedOp, message: &GetAcceptedFrontierFailed{ - ChainID: chainID, - RequestID: requestID, - EngineType: engineType, + ChainID: chainID, + RequestID: requestID, }, expiration: mockable.MaxTime, } } type GetAcceptedFailed struct { - ChainID ids.ID `json:"chain_id,omitempty"` - RequestID uint32 `json:"request_id,omitempty"` - EngineType p2p.EngineType `json:"engine_type,omitempty"` + ChainID ids.ID `json:"chain_id,omitempty"` + RequestID uint32 `json:"request_id,omitempty"` } func (m *GetAcceptedFailed) String() string { return fmt.Sprintf( - "ChainID: %s RequestID: %d EngineType: %s", - m.ChainID, m.RequestID, m.EngineType, + "ChainID: %s RequestID: %d", + m.ChainID, m.RequestID, ) } @@ -210,23 +198,17 @@ func (m *GetAcceptedFailed) GetRequestId() uint32 { return m.RequestID } -func (m *GetAcceptedFailed) GetEngineType() p2p.EngineType { - return m.EngineType -} - func InternalGetAcceptedFailed( nodeID ids.NodeID, chainID ids.ID, requestID uint32, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, op: GetAcceptedFailedOp, message: &GetAcceptedFailed{ - ChainID: chainID, - RequestID: requestID, - EngineType: engineType, + ChainID: chainID, + RequestID: requestID, }, expiration: mockable.MaxTime, } @@ -276,15 +258,14 @@ func InternalGetAncestorsFailed( } type GetFailed struct { - ChainID ids.ID `json:"chain_id,omitempty"` - RequestID uint32 `json:"request_id,omitempty"` - EngineType p2p.EngineType `json:"engine_type,omitempty"` + ChainID ids.ID `json:"chain_id,omitempty"` + RequestID uint32 `json:"request_id,omitempty"` } func (m *GetFailed) String() string { return fmt.Sprintf( - "ChainID: %s RequestID: %d EngineType: %s", - m.ChainID, m.RequestID, m.EngineType, + "ChainID: %s RequestID: %d", + m.ChainID, m.RequestID, ) } @@ -296,38 +277,31 @@ func (m *GetFailed) GetRequestId() uint32 { return m.RequestID } -func (m *GetFailed) GetEngineType() p2p.EngineType { - return m.EngineType -} - func InternalGetFailed( nodeID ids.NodeID, chainID ids.ID, requestID uint32, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, op: GetFailedOp, message: &GetFailed{ - ChainID: chainID, - RequestID: requestID, - EngineType: engineType, + ChainID: chainID, + RequestID: requestID, }, expiration: mockable.MaxTime, } } type QueryFailed struct { - ChainID ids.ID `json:"chain_id,omitempty"` - RequestID uint32 `json:"request_id,omitempty"` - EngineType p2p.EngineType `json:"engine_type,omitempty"` + ChainID ids.ID `json:"chain_id,omitempty"` + RequestID uint32 `json:"request_id,omitempty"` } func (m *QueryFailed) String() string { return fmt.Sprintf( - "ChainID: %s RequestID: %d EngineType: %s", - m.ChainID, m.RequestID, m.EngineType, + "ChainID: %s RequestID: %d", + m.ChainID, m.RequestID, ) } @@ -339,23 +313,17 @@ func (m *QueryFailed) GetRequestId() uint32 { return m.RequestID } -func (m *QueryFailed) GetEngineType() p2p.EngineType { - return m.EngineType -} - func InternalQueryFailed( nodeID ids.NodeID, chainID ids.ID, requestID uint32, - engineType p2p.EngineType, ) InboundMessage { return &inboundMessage{ nodeID: nodeID, op: QueryFailedOp, message: &QueryFailed{ - ChainID: chainID, - RequestID: requestID, - EngineType: engineType, + ChainID: chainID, + RequestID: requestID, }, expiration: mockable.MaxTime, } diff --git a/message/messages_test.go b/message/messages_test.go index ea2a41e160f7..d469d636e934 100644 --- a/message/messages_test.go +++ b/message/messages_test.go @@ -338,10 +338,9 @@ func TestMessage(t *testing.T) { msg: &p2p.Message{ Message: &p2p.Message_GetAcceptedFrontier{ GetAcceptedFrontier: &p2p.GetAcceptedFrontier{ - ChainId: testID[:], - RequestId: 1, - Deadline: 1, - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, + ChainId: testID[:], + RequestId: 1, + Deadline: 1, }, }, }, @@ -375,7 +374,6 @@ func TestMessage(t *testing.T) { RequestId: 1, Deadline: 1, ContainerIds: [][]byte{testID[:], testID[:]}, - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, }, }, }, @@ -459,7 +457,6 @@ func TestMessage(t *testing.T) { RequestId: 1, Deadline: 1, ContainerId: testID[:], - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, }, }, }, @@ -473,10 +470,9 @@ func TestMessage(t *testing.T) { msg: &p2p.Message{ Message: &p2p.Message_Put{ Put: &p2p.Put{ - ChainId: testID[:], - RequestId: 1, - Container: []byte{0}, - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, + ChainId: testID[:], + RequestId: 1, + Container: []byte{0}, }, }, }, @@ -490,10 +486,9 @@ func TestMessage(t *testing.T) { msg: &p2p.Message{ Message: &p2p.Message_Put{ Put: &p2p.Put{ - ChainId: testID[:], - RequestId: 1, - Container: compressibleContainers[0], - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, + ChainId: testID[:], + RequestId: 1, + Container: compressibleContainers[0], }, }, }, @@ -507,11 +502,10 @@ func TestMessage(t *testing.T) { msg: &p2p.Message{ Message: &p2p.Message_PushQuery{ PushQuery: &p2p.PushQuery{ - ChainId: testID[:], - RequestId: 1, - Deadline: 1, - Container: []byte{0}, - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, + ChainId: testID[:], + RequestId: 1, + Deadline: 1, + Container: []byte{0}, }, }, }, @@ -525,11 +519,10 @@ func TestMessage(t *testing.T) { msg: &p2p.Message{ Message: &p2p.Message_PushQuery{ PushQuery: &p2p.PushQuery{ - ChainId: testID[:], - RequestId: 1, - Deadline: 1, - Container: compressibleContainers[0], - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, + ChainId: testID[:], + RequestId: 1, + Deadline: 1, + Container: compressibleContainers[0], }, }, }, @@ -547,7 +540,6 @@ func TestMessage(t *testing.T) { RequestId: 1, Deadline: 1, ContainerId: testID[:], - EngineType: p2p.EngineType_ENGINE_TYPE_AVALANCHE, }, }, }, diff --git a/message/mock_outbound_message_builder.go b/message/mock_outbound_message_builder.go index 1e7a52265a62..3d8dbba6594c 100644 --- a/message/mock_outbound_message_builder.go +++ b/message/mock_outbound_message_builder.go @@ -178,48 +178,48 @@ func (mr *MockOutboundMsgBuilderMockRecorder) Chits(arg0, arg1, arg2, arg3, arg4 } // Get mocks base method. -func (m *MockOutboundMsgBuilder) Get(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 ids.ID, arg4 p2p.EngineType) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) Get(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 ids.ID) (OutboundMessage, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "Get", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(OutboundMessage) ret1, _ := ret[1].(error) return ret0, ret1 } // Get indicates an expected call of Get. -func (mr *MockOutboundMsgBuilderMockRecorder) Get(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockOutboundMsgBuilderMockRecorder) Get(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).Get), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Get", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).Get), arg0, arg1, arg2, arg3) } // GetAccepted mocks base method. -func (m *MockOutboundMsgBuilder) GetAccepted(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 []ids.ID, arg4 p2p.EngineType) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) GetAccepted(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 []ids.ID) (OutboundMessage, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAccepted", arg0, arg1, arg2, arg3, arg4) + ret := m.ctrl.Call(m, "GetAccepted", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(OutboundMessage) ret1, _ := ret[1].(error) return ret0, ret1 } // GetAccepted indicates an expected call of GetAccepted. -func (mr *MockOutboundMsgBuilderMockRecorder) GetAccepted(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { +func (mr *MockOutboundMsgBuilderMockRecorder) GetAccepted(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccepted", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).GetAccepted), arg0, arg1, arg2, arg3, arg4) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAccepted", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).GetAccepted), arg0, arg1, arg2, arg3) } // GetAcceptedFrontier mocks base method. -func (m *MockOutboundMsgBuilder) GetAcceptedFrontier(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 p2p.EngineType) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) GetAcceptedFrontier(arg0 ids.ID, arg1 uint32, arg2 time.Duration) (OutboundMessage, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetAcceptedFrontier", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "GetAcceptedFrontier", arg0, arg1, arg2) ret0, _ := ret[0].(OutboundMessage) ret1, _ := ret[1].(error) return ret0, ret1 } // GetAcceptedFrontier indicates an expected call of GetAcceptedFrontier. -func (mr *MockOutboundMsgBuilderMockRecorder) GetAcceptedFrontier(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockOutboundMsgBuilderMockRecorder) GetAcceptedFrontier(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAcceptedFrontier", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).GetAcceptedFrontier), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAcceptedFrontier", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).GetAcceptedFrontier), arg0, arg1, arg2) } // GetAcceptedStateSummary mocks base method. @@ -343,48 +343,48 @@ func (mr *MockOutboundMsgBuilderMockRecorder) Pong(arg0, arg1 any) *gomock.Call } // PullQuery mocks base method. -func (m *MockOutboundMsgBuilder) PullQuery(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 ids.ID, arg4 uint64, arg5 p2p.EngineType) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) PullQuery(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 ids.ID, arg4 uint64) (OutboundMessage, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PullQuery", arg0, arg1, arg2, arg3, arg4, arg5) + ret := m.ctrl.Call(m, "PullQuery", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(OutboundMessage) ret1, _ := ret[1].(error) return ret0, ret1 } // PullQuery indicates an expected call of PullQuery. -func (mr *MockOutboundMsgBuilderMockRecorder) PullQuery(arg0, arg1, arg2, arg3, arg4, arg5 any) *gomock.Call { +func (mr *MockOutboundMsgBuilderMockRecorder) PullQuery(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PullQuery", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).PullQuery), arg0, arg1, arg2, arg3, arg4, arg5) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PullQuery", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).PullQuery), arg0, arg1, arg2, arg3, arg4) } // PushQuery mocks base method. -func (m *MockOutboundMsgBuilder) PushQuery(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 []byte, arg4 uint64, arg5 p2p.EngineType) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) PushQuery(arg0 ids.ID, arg1 uint32, arg2 time.Duration, arg3 []byte, arg4 uint64) (OutboundMessage, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PushQuery", arg0, arg1, arg2, arg3, arg4, arg5) + ret := m.ctrl.Call(m, "PushQuery", arg0, arg1, arg2, arg3, arg4) ret0, _ := ret[0].(OutboundMessage) ret1, _ := ret[1].(error) return ret0, ret1 } // PushQuery indicates an expected call of PushQuery. -func (mr *MockOutboundMsgBuilderMockRecorder) PushQuery(arg0, arg1, arg2, arg3, arg4, arg5 any) *gomock.Call { +func (mr *MockOutboundMsgBuilderMockRecorder) PushQuery(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PushQuery", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).PushQuery), arg0, arg1, arg2, arg3, arg4, arg5) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PushQuery", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).PushQuery), arg0, arg1, arg2, arg3, arg4) } // Put mocks base method. -func (m *MockOutboundMsgBuilder) Put(arg0 ids.ID, arg1 uint32, arg2 []byte, arg3 p2p.EngineType) (OutboundMessage, error) { +func (m *MockOutboundMsgBuilder) Put(arg0 ids.ID, arg1 uint32, arg2 []byte) (OutboundMessage, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Put", arg0, arg1, arg2, arg3) + ret := m.ctrl.Call(m, "Put", arg0, arg1, arg2) ret0, _ := ret[0].(OutboundMessage) ret1, _ := ret[1].(error) return ret0, ret1 } // Put indicates an expected call of Put. -func (mr *MockOutboundMsgBuilderMockRecorder) Put(arg0, arg1, arg2, arg3 any) *gomock.Call { +func (mr *MockOutboundMsgBuilderMockRecorder) Put(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).Put), arg0, arg1, arg2, arg3) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Put", reflect.TypeOf((*MockOutboundMsgBuilder)(nil).Put), arg0, arg1, arg2) } // StateSummaryFrontier mocks base method. diff --git a/message/outbound_msg_builder.go b/message/outbound_msg_builder.go index 3e5925c65ecc..8e5261f14775 100644 --- a/message/outbound_msg_builder.go +++ b/message/outbound_msg_builder.go @@ -85,7 +85,6 @@ type OutboundMsgBuilder interface { chainID ids.ID, requestID uint32, deadline time.Duration, - engineType p2p.EngineType, ) (OutboundMessage, error) AcceptedFrontier( @@ -99,7 +98,6 @@ type OutboundMsgBuilder interface { requestID uint32, deadline time.Duration, containerIDs []ids.ID, - engineType p2p.EngineType, ) (OutboundMessage, error) Accepted( @@ -127,14 +125,12 @@ type OutboundMsgBuilder interface { requestID uint32, deadline time.Duration, containerID ids.ID, - engineType p2p.EngineType, ) (OutboundMessage, error) Put( chainID ids.ID, requestID uint32, container []byte, - engineType p2p.EngineType, ) (OutboundMessage, error) PushQuery( @@ -143,7 +139,6 @@ type OutboundMsgBuilder interface { deadline time.Duration, container []byte, requestedHeight uint64, - engineType p2p.EngineType, ) (OutboundMessage, error) PullQuery( @@ -152,7 +147,6 @@ type OutboundMsgBuilder interface { deadline time.Duration, containerID ids.ID, requestedHeight uint64, - engineType p2p.EngineType, ) (OutboundMessage, error) Chits( @@ -424,16 +418,14 @@ func (b *outMsgBuilder) GetAcceptedFrontier( chainID ids.ID, requestID uint32, deadline time.Duration, - engineType p2p.EngineType, ) (OutboundMessage, error) { return b.builder.createOutbound( &p2p.Message{ Message: &p2p.Message_GetAcceptedFrontier{ GetAcceptedFrontier: &p2p.GetAcceptedFrontier{ - ChainId: chainID[:], - RequestId: requestID, - Deadline: uint64(deadline), - EngineType: engineType, + ChainId: chainID[:], + RequestId: requestID, + Deadline: uint64(deadline), }, }, }, @@ -467,7 +459,6 @@ func (b *outMsgBuilder) GetAccepted( requestID uint32, deadline time.Duration, containerIDs []ids.ID, - engineType p2p.EngineType, ) (OutboundMessage, error) { containerIDBytes := make([][]byte, len(containerIDs)) encodeIDs(containerIDs, containerIDBytes) @@ -479,7 +470,6 @@ func (b *outMsgBuilder) GetAccepted( RequestId: requestID, Deadline: uint64(deadline), ContainerIds: containerIDBytes, - EngineType: engineType, }, }, }, @@ -559,7 +549,6 @@ func (b *outMsgBuilder) Get( requestID uint32, deadline time.Duration, containerID ids.ID, - engineType p2p.EngineType, ) (OutboundMessage, error) { return b.builder.createOutbound( &p2p.Message{ @@ -569,7 +558,6 @@ func (b *outMsgBuilder) Get( RequestId: requestID, Deadline: uint64(deadline), ContainerId: containerID[:], - EngineType: engineType, }, }, }, @@ -582,16 +570,14 @@ func (b *outMsgBuilder) Put( chainID ids.ID, requestID uint32, container []byte, - engineType p2p.EngineType, ) (OutboundMessage, error) { return b.builder.createOutbound( &p2p.Message{ Message: &p2p.Message_Put{ Put: &p2p.Put{ - ChainId: chainID[:], - RequestId: requestID, - Container: container, - EngineType: engineType, + ChainId: chainID[:], + RequestId: requestID, + Container: container, }, }, }, @@ -606,7 +592,6 @@ func (b *outMsgBuilder) PushQuery( deadline time.Duration, container []byte, requestedHeight uint64, - engineType p2p.EngineType, ) (OutboundMessage, error) { return b.builder.createOutbound( &p2p.Message{ @@ -617,7 +602,6 @@ func (b *outMsgBuilder) PushQuery( Deadline: uint64(deadline), Container: container, RequestedHeight: requestedHeight, - EngineType: engineType, }, }, }, @@ -632,7 +616,6 @@ func (b *outMsgBuilder) PullQuery( deadline time.Duration, containerID ids.ID, requestedHeight uint64, - engineType p2p.EngineType, ) (OutboundMessage, error) { return b.builder.createOutbound( &p2p.Message{ @@ -643,7 +626,6 @@ func (b *outMsgBuilder) PullQuery( Deadline: uint64(deadline), ContainerId: containerID[:], RequestedHeight: requestedHeight, - EngineType: engineType, }, }, }, diff --git a/network/network_test.go b/network/network_test.go index 447a58df14a2..ee645aef21d7 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -20,7 +20,6 @@ import ( "github.com/ava-labs/avalanchego/network/dialer" "github.com/ava-labs/avalanchego/network/peer" "github.com/ava-labs/avalanchego/network/throttling" - "github.com/ava-labs/avalanchego/proto/pb/p2p" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/snow/networking/router" "github.com/ava-labs/avalanchego/snow/networking/tracker" @@ -324,7 +323,7 @@ func TestSend(t *testing.T) { net0 := networks[0] mc := newMessageCreator(t) - outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty, p2p.EngineType_ENGINE_TYPE_SNOWMAN) + outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty) require.NoError(err) toSend := set.Of(nodeIDs[1]) @@ -369,7 +368,7 @@ func TestSendWithFilter(t *testing.T) { net0 := networks[0] mc := newMessageCreator(t) - outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty, p2p.EngineType_ENGINE_TYPE_SNOWMAN) + outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty) require.NoError(err) toSend := set.Of(nodeIDs...) diff --git a/network/peer/peer_test.go b/network/peer/peer_test.go index c354013e64cc..96d6ddb7b98b 100644 --- a/network/peer/peer_test.go +++ b/network/peer/peer_test.go @@ -258,7 +258,7 @@ func TestSend(t *testing.T) { peer0, peer1 := makeReadyTestPeers(t, set.Set[ids.ID]{}) mc := newMessageCreator(t) - outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty, p2p.EngineType_ENGINE_TYPE_SNOWMAN) + outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty) require.NoError(err) require.True(peer0.Send(context.Background(), outboundGetMsg)) @@ -751,7 +751,7 @@ func TestShouldDisconnect(t *testing.T) { func sendAndFlush(t *testing.T, sender *testPeer, receiver *testPeer) { t.Helper() mc := newMessageCreator(t) - outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty, p2p.EngineType_ENGINE_TYPE_SNOWMAN) + outboundGetMsg, err := mc.Get(ids.Empty, 1, time.Second, ids.Empty) require.NoError(t, err) require.True(t, sender.Send(context.Background(), outboundGetMsg)) inboundGetMsg := <-receiver.inboundMsgChan diff --git a/proto/p2p/p2p.proto b/proto/p2p/p2p.proto index 0cbfec212a7d..aa60c6db34de 100644 --- a/proto/p2p/p2p.proto +++ b/proto/p2p/p2p.proto @@ -231,14 +231,13 @@ enum EngineType { // // Peers should respond to GetAcceptedFrontier with AcceptedFrontier. message GetAcceptedFrontier { + reserved 4; // Chain being requested from bytes chain_id = 1; // Unique identifier for this request uint32 request_id = 2; // Timeout (ns) for this request uint64 deadline = 3; - // Consensus type the remote peer should use to handle this message - EngineType engine_type = 4; } // AcceptedFrontier contains the remote peer's last accepted frontier. @@ -258,6 +257,7 @@ message AcceptedFrontier { // // Peers should respond to GetAccepted with an Accepted message. message GetAccepted { + reserved 5; // Chain being requested from bytes chain_id = 1; // Unique identifier for this message @@ -266,8 +266,6 @@ message GetAccepted { uint64 deadline = 3; // The sender's accepted frontier repeated bytes container_ids = 4; - // Consensus type to handle this message - EngineType engine_type = 5; } // Accepted is sent in response to GetAccepted. The sending peer responds with @@ -316,6 +314,7 @@ message Ancestors { // // Remote peers should respond with a Put message if they have the container. message Get { + reserved 5; // Chain being requested from bytes chain_id = 1; // Unique identifier for this request @@ -324,8 +323,6 @@ message Get { uint64 deadline = 3; // Container being requested bytes container_id = 4; - // Consensus type to handle this message - EngineType engine_type = 5; } // Put is sent in response to Get with the requested block. @@ -336,14 +333,13 @@ message Put { uint32 request_id = 2; // Requested container bytes container = 3; - // Consensus type to handle this message - EngineType engine_type = 4; } // PushQuery requests the preferences of a remote peer given a container. // // Remote peers should respond to a PushQuery with a Chits message message PushQuery { + reserved 5; // Chain being requested from bytes chain_id = 1; // Unique identifier for this request @@ -352,8 +348,6 @@ message PushQuery { uint64 deadline = 3; // Container being gossiped bytes container = 4; - // Consensus type to handle this message - EngineType engine_type = 5; // Requesting peer's last accepted height uint64 requested_height = 6; } @@ -362,6 +356,7 @@ message PushQuery { // // Remote peers should respond to a PullQuery with a Chits message message PullQuery { + reserved 5; // Chain being requested from bytes chain_id = 1; // Unique identifier for this request @@ -370,8 +365,6 @@ message PullQuery { uint64 deadline = 3; // Container id being gossiped bytes container_id = 4; - // Consensus type to handle this message - EngineType engine_type = 5; // Requesting peer's last accepted height uint64 requested_height = 6; } diff --git a/proto/pb/p2p/p2p.pb.go b/proto/pb/p2p/p2p.pb.go index 70da9351128e..e3b1f5d86888 100644 --- a/proto/pb/p2p/p2p.pb.go +++ b/proto/pb/p2p/p2p.pb.go @@ -1445,8 +1445,6 @@ type GetAcceptedFrontier struct { RequestId uint32 `protobuf:"varint,2,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` // Timeout (ns) for this request Deadline uint64 `protobuf:"varint,3,opt,name=deadline,proto3" json:"deadline,omitempty"` - // Consensus type the remote peer should use to handle this message - EngineType EngineType `protobuf:"varint,4,opt,name=engine_type,json=engineType,proto3,enum=p2p.EngineType" json:"engine_type,omitempty"` } func (x *GetAcceptedFrontier) Reset() { @@ -1502,13 +1500,6 @@ func (x *GetAcceptedFrontier) GetDeadline() uint64 { return 0 } -func (x *GetAcceptedFrontier) GetEngineType() EngineType { - if x != nil { - return x.EngineType - } - return EngineType_ENGINE_TYPE_UNSPECIFIED -} - // AcceptedFrontier contains the remote peer's last accepted frontier. // // AcceptedFrontier is sent in response to GetAcceptedFrontier. @@ -1595,8 +1586,6 @@ type GetAccepted struct { Deadline uint64 `protobuf:"varint,3,opt,name=deadline,proto3" json:"deadline,omitempty"` // The sender's accepted frontier ContainerIds [][]byte `protobuf:"bytes,4,rep,name=container_ids,json=containerIds,proto3" json:"container_ids,omitempty"` - // Consensus type to handle this message - EngineType EngineType `protobuf:"varint,5,opt,name=engine_type,json=engineType,proto3,enum=p2p.EngineType" json:"engine_type,omitempty"` } func (x *GetAccepted) Reset() { @@ -1659,13 +1648,6 @@ func (x *GetAccepted) GetContainerIds() [][]byte { return nil } -func (x *GetAccepted) GetEngineType() EngineType { - if x != nil { - return x.EngineType - } - return EngineType_ENGINE_TYPE_UNSPECIFIED -} - // Accepted is sent in response to GetAccepted. The sending peer responds with // a subset of container ids from the GetAccepted request that the sending peer // has accepted. @@ -1909,8 +1891,6 @@ type Get struct { Deadline uint64 `protobuf:"varint,3,opt,name=deadline,proto3" json:"deadline,omitempty"` // Container being requested ContainerId []byte `protobuf:"bytes,4,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` - // Consensus type to handle this message - EngineType EngineType `protobuf:"varint,5,opt,name=engine_type,json=engineType,proto3,enum=p2p.EngineType" json:"engine_type,omitempty"` } func (x *Get) Reset() { @@ -1973,13 +1953,6 @@ func (x *Get) GetContainerId() []byte { return nil } -func (x *Get) GetEngineType() EngineType { - if x != nil { - return x.EngineType - } - return EngineType_ENGINE_TYPE_UNSPECIFIED -} - // Put is sent in response to Get with the requested block. type Put struct { state protoimpl.MessageState @@ -1992,8 +1965,6 @@ type Put struct { RequestId uint32 `protobuf:"varint,2,opt,name=request_id,json=requestId,proto3" json:"request_id,omitempty"` // Requested container Container []byte `protobuf:"bytes,3,opt,name=container,proto3" json:"container,omitempty"` - // Consensus type to handle this message - EngineType EngineType `protobuf:"varint,4,opt,name=engine_type,json=engineType,proto3,enum=p2p.EngineType" json:"engine_type,omitempty"` } func (x *Put) Reset() { @@ -2049,13 +2020,6 @@ func (x *Put) GetContainer() []byte { return nil } -func (x *Put) GetEngineType() EngineType { - if x != nil { - return x.EngineType - } - return EngineType_ENGINE_TYPE_UNSPECIFIED -} - // PushQuery requests the preferences of a remote peer given a container. // // Remote peers should respond to a PushQuery with a Chits message @@ -2072,8 +2036,6 @@ type PushQuery struct { Deadline uint64 `protobuf:"varint,3,opt,name=deadline,proto3" json:"deadline,omitempty"` // Container being gossiped Container []byte `protobuf:"bytes,4,opt,name=container,proto3" json:"container,omitempty"` - // Consensus type to handle this message - EngineType EngineType `protobuf:"varint,5,opt,name=engine_type,json=engineType,proto3,enum=p2p.EngineType" json:"engine_type,omitempty"` // Requesting peer's last accepted height RequestedHeight uint64 `protobuf:"varint,6,opt,name=requested_height,json=requestedHeight,proto3" json:"requested_height,omitempty"` } @@ -2138,13 +2100,6 @@ func (x *PushQuery) GetContainer() []byte { return nil } -func (x *PushQuery) GetEngineType() EngineType { - if x != nil { - return x.EngineType - } - return EngineType_ENGINE_TYPE_UNSPECIFIED -} - func (x *PushQuery) GetRequestedHeight() uint64 { if x != nil { return x.RequestedHeight @@ -2168,8 +2123,6 @@ type PullQuery struct { Deadline uint64 `protobuf:"varint,3,opt,name=deadline,proto3" json:"deadline,omitempty"` // Container id being gossiped ContainerId []byte `protobuf:"bytes,4,opt,name=container_id,json=containerId,proto3" json:"container_id,omitempty"` - // Consensus type to handle this message - EngineType EngineType `protobuf:"varint,5,opt,name=engine_type,json=engineType,proto3,enum=p2p.EngineType" json:"engine_type,omitempty"` // Requesting peer's last accepted height RequestedHeight uint64 `protobuf:"varint,6,opt,name=requested_height,json=requestedHeight,proto3" json:"requested_height,omitempty"` } @@ -2234,13 +2187,6 @@ func (x *PullQuery) GetContainerId() []byte { return nil } -func (x *PullQuery) GetEngineType() EngineType { - if x != nil { - return x.EngineType - } - return EngineType_ENGINE_TYPE_UNSPECIFIED -} - func (x *PullQuery) GetRequestedHeight() uint64 { if x != nil { return x.RequestedHeight @@ -2808,44 +2754,82 @@ var file_p2p_p2p_proto_rawDesc = []byte{ 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, - 0x52, 0x0a, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x49, 0x64, 0x73, 0x22, 0x9d, 0x01, 0x0a, - 0x13, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, 0x6e, - 0x74, 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, - 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, - 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, - 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, - 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, - 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x6f, 0x0a, 0x10, - 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, + 0x52, 0x0a, 0x73, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x49, 0x64, 0x73, 0x22, 0x71, 0x0a, 0x13, + 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, 0x6e, 0x74, + 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, + 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, + 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, 0x22, + 0x6f, 0x0a, 0x10, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x46, 0x72, 0x6f, 0x6e, 0x74, + 0x69, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, + 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, + 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, + 0x22, 0x8e, 0x01, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x22, 0xba, 0x01, - 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, + 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, + 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, + 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, 0x63, + 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x4a, 0x04, 0x08, 0x05, 0x10, + 0x06, 0x22, 0x69, 0x0a, 0x08, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, + 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, + 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x22, 0xb9, 0x01, 0x0a, + 0x0c, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, - 0x69, 0x6e, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, - 0x5f, 0x69, 0x64, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x73, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, - 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, - 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, - 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x69, 0x0a, 0x08, 0x41, 0x63, - 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, - 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, - 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, - 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, - 0x65, 0x72, 0x49, 0x64, 0x73, 0x22, 0xb9, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x41, 0x6e, 0x63, - 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, + 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, + 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, + 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, + 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x65, 0x0a, 0x09, 0x41, 0x6e, 0x63, 0x65, + 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, + 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, + 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x22, + 0x84, 0x01, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, + 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, + 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, + 0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x22, 0x5d, 0x0a, 0x03, 0x50, 0x75, 0x74, 0x12, 0x19, 0x0a, + 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, + 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x74, + 0x61, 0x69, 0x6e, 0x65, 0x72, 0x22, 0xb0, 0x01, 0x0a, 0x09, 0x50, 0x75, 0x73, 0x68, 0x51, 0x75, + 0x65, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, + 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, + 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x65, 0x64, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, 0x67, + 0x68, 0x74, 0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x22, 0xb5, 0x01, 0x0a, 0x09, 0x50, 0x75, 0x6c, + 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, @@ -2853,64 +2837,9 @@ var file_p2p_p2p_proto_rawDesc = []byte{ 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, - 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x22, 0x65, 0x0a, 0x09, 0x41, 0x6e, 0x63, 0x65, 0x73, 0x74, 0x6f, 0x72, 0x73, 0x12, 0x19, - 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, - 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x22, 0xb0, 0x01, 0x0a, 0x03, 0x47, 0x65, 0x74, - 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, - 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, - 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, - 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, - 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, - 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, - 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0x8f, 0x01, 0x0a, 0x03, - 0x50, 0x75, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, - 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1c, 0x0a, - 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, - 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x30, 0x0a, 0x0b, 0x65, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0e, - 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x22, 0xdc, 0x01, - 0x0a, 0x09, 0x50, 0x75, 0x73, 0x68, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, - 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, - 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, - 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, - 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x68, - 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x72, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x22, 0xe1, 0x01, 0x0a, - 0x09, 0x50, 0x75, 0x6c, 0x6c, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, - 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x72, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, - 0x12, 0x21, 0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x64, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a, 0x0b, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x5f, 0x74, 0x79, - 0x70, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x70, 0x32, 0x70, 0x2e, 0x45, - 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0a, 0x65, 0x6e, 0x67, 0x69, 0x6e, - 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x65, 0x64, 0x5f, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x0f, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, + 0x29, 0x0a, 0x10, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x65, 0x64, 0x5f, 0x68, 0x65, 0x69, + 0x67, 0x68, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x65, 0x64, 0x48, 0x65, 0x69, 0x67, 0x68, 0x74, 0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x22, 0xba, 0x01, 0x0a, 0x05, 0x43, 0x68, 0x69, 0x74, 0x73, 0x12, 0x19, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, @@ -3039,18 +2968,12 @@ var file_p2p_p2p_proto_depIdxs = []int32{ 7, // 27: p2p.Handshake.known_peers:type_name -> p2p.BloomFilter 7, // 28: p2p.GetPeerList.known_peers:type_name -> p2p.BloomFilter 8, // 29: p2p.PeerList.claimed_ip_ports:type_name -> p2p.ClaimedIpPort - 0, // 30: p2p.GetAcceptedFrontier.engine_type:type_name -> p2p.EngineType - 0, // 31: p2p.GetAccepted.engine_type:type_name -> p2p.EngineType - 0, // 32: p2p.GetAncestors.engine_type:type_name -> p2p.EngineType - 0, // 33: p2p.Get.engine_type:type_name -> p2p.EngineType - 0, // 34: p2p.Put.engine_type:type_name -> p2p.EngineType - 0, // 35: p2p.PushQuery.engine_type:type_name -> p2p.EngineType - 0, // 36: p2p.PullQuery.engine_type:type_name -> p2p.EngineType - 37, // [37:37] is the sub-list for method output_type - 37, // [37:37] is the sub-list for method input_type - 37, // [37:37] is the sub-list for extension type_name - 37, // [37:37] is the sub-list for extension extendee - 0, // [0:37] is the sub-list for field type_name + 0, // 30: p2p.GetAncestors.engine_type:type_name -> p2p.EngineType + 31, // [31:31] is the sub-list for method output_type + 31, // [31:31] is the sub-list for method input_type + 31, // [31:31] is the sub-list for extension type_name + 31, // [31:31] is the sub-list for extension extendee + 0, // [0:31] is the sub-list for field type_name } func init() { file_p2p_p2p_proto_init() } diff --git a/snow/engine/avalanche/getter/getter.go b/snow/engine/avalanche/getter/getter.go index a8e35fddfd64..796cade92fac 100644 --- a/snow/engine/avalanche/getter/getter.go +++ b/snow/engine/avalanche/getter/getter.go @@ -82,27 +82,23 @@ func (gh *getter) GetAcceptedStateSummary(_ context.Context, nodeID ids.NodeID, return nil } -// TODO: Remove support for GetAcceptedFrontier messages after v1.11.x is -// activated. -func (gh *getter) GetAcceptedFrontier(ctx context.Context, validatorID ids.NodeID, requestID uint32) error { - acceptedFrontier := gh.storage.Edge(ctx) - // Since all the DAGs are linearized, we only need to return the stop - // vertex. - if len(acceptedFrontier) > 0 { - gh.sender.SendAcceptedFrontier(ctx, validatorID, requestID, acceptedFrontier[0]) - } +func (gh *getter) GetAcceptedFrontier(_ context.Context, nodeID ids.NodeID, requestID uint32) error { + gh.log.Debug("dropping request", + zap.String("reason", "unhandled by this gear"), + zap.Stringer("messageOp", message.GetAcceptedFrontierOp), + zap.Stringer("nodeID", nodeID), + zap.Uint32("requestID", requestID), + ) return nil } -// TODO: Remove support for GetAccepted messages after v1.11.x is activated. -func (gh *getter) GetAccepted(ctx context.Context, nodeID ids.NodeID, requestID uint32, containerIDs set.Set[ids.ID]) error { - acceptedVtxIDs := make([]ids.ID, 0, containerIDs.Len()) - for vtxID := range containerIDs { - if vtx, err := gh.storage.GetVtx(ctx, vtxID); err == nil && vtx.Status() == choices.Accepted { - acceptedVtxIDs = append(acceptedVtxIDs, vtxID) - } - } - gh.sender.SendAccepted(ctx, nodeID, requestID, acceptedVtxIDs) +func (gh *getter) GetAccepted(_ context.Context, nodeID ids.NodeID, requestID uint32, _ set.Set[ids.ID]) error { + gh.log.Debug("dropping request", + zap.String("reason", "unhandled by this gear"), + zap.Stringer("messageOp", message.GetAcceptedOp), + zap.Stringer("nodeID", nodeID), + zap.Uint32("requestID", requestID), + ) return nil } @@ -158,10 +154,12 @@ func (gh *getter) GetAncestors(ctx context.Context, nodeID ids.NodeID, requestID return nil } -func (gh *getter) Get(ctx context.Context, nodeID ids.NodeID, requestID uint32, vtxID ids.ID) error { - // If this engine has access to the requested vertex, provide it - if vtx, err := gh.storage.GetVtx(ctx, vtxID); err == nil { - gh.sender.SendPut(ctx, nodeID, requestID, vtx.Bytes()) - } +func (gh *getter) Get(_ context.Context, nodeID ids.NodeID, requestID uint32, _ ids.ID) error { + gh.log.Debug("dropping request", + zap.String("reason", "unhandled by this gear"), + zap.Stringer("messageOp", message.GetOp), + zap.Stringer("nodeID", nodeID), + zap.Uint32("requestID", requestID), + ) return nil } diff --git a/snow/engine/avalanche/getter/getter_test.go b/snow/engine/avalanche/getter/getter_test.go deleted file mode 100644 index c052d0bc3a83..000000000000 --- a/snow/engine/avalanche/getter/getter_test.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package getter - -import ( - "context" - "errors" - "testing" - "time" - - "github.com/prometheus/client_golang/prometheus" - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/snow/choices" - "github.com/ava-labs/avalanchego/snow/consensus/avalanche" - "github.com/ava-labs/avalanchego/snow/engine/avalanche/vertex" - "github.com/ava-labs/avalanchego/snow/engine/common" - "github.com/ava-labs/avalanchego/utils/logging" - "github.com/ava-labs/avalanchego/utils/set" -) - -var errUnknownVertex = errors.New("unknown vertex") - -func newTest(t *testing.T) (common.AllGetsServer, *vertex.TestManager, *common.SenderTest) { - manager := vertex.NewTestManager(t) - manager.Default(true) - - sender := &common.SenderTest{ - T: t, - } - sender.Default(true) - - bs, err := New( - manager, - sender, - logging.NoLog{}, - time.Second, - 2000, - prometheus.NewRegistry(), - ) - require.NoError(t, err) - - return bs, manager, sender -} - -func TestAcceptedFrontier(t *testing.T) { - require := require.New(t) - bs, manager, sender := newTest(t) - - vtxID := ids.GenerateTestID() - manager.EdgeF = func(context.Context) []ids.ID { - return []ids.ID{ - vtxID, - } - } - - var accepted ids.ID - sender.SendAcceptedFrontierF = func(_ context.Context, _ ids.NodeID, _ uint32, containerID ids.ID) { - accepted = containerID - } - require.NoError(bs.GetAcceptedFrontier(context.Background(), ids.EmptyNodeID, 0)) - require.Equal(vtxID, accepted) -} - -func TestFilterAccepted(t *testing.T) { - require := require.New(t) - bs, manager, sender := newTest(t) - - vtxID0 := ids.GenerateTestID() - vtxID1 := ids.GenerateTestID() - vtxID2 := ids.GenerateTestID() - - vtx0 := &avalanche.TestVertex{TestDecidable: choices.TestDecidable{ - IDV: vtxID0, - StatusV: choices.Accepted, - }} - vtx1 := &avalanche.TestVertex{TestDecidable: choices.TestDecidable{ - IDV: vtxID1, - StatusV: choices.Accepted, - }} - - manager.GetVtxF = func(_ context.Context, vtxID ids.ID) (avalanche.Vertex, error) { - switch vtxID { - case vtxID0: - return vtx0, nil - case vtxID1: - return vtx1, nil - case vtxID2: - return nil, errUnknownVertex - } - require.FailNow(errUnknownVertex.Error()) - return nil, errUnknownVertex - } - - var accepted []ids.ID - sender.SendAcceptedF = func(_ context.Context, _ ids.NodeID, _ uint32, frontier []ids.ID) { - accepted = frontier - } - - vtxIDs := set.Of(vtxID0, vtxID1, vtxID2) - require.NoError(bs.GetAccepted(context.Background(), ids.EmptyNodeID, 0, vtxIDs)) - - require.Contains(accepted, vtxID0) - require.Contains(accepted, vtxID1) - require.NotContains(accepted, vtxID2) -} diff --git a/snow/networking/handler/handler_test.go b/snow/networking/handler/handler_test.go index dbf378c0d366..71809bd953f6 100644 --- a/snow/networking/handler/handler_test.go +++ b/snow/networking/handler/handler_test.go @@ -101,8 +101,8 @@ func TestHandlerDropsTimedOutMessages(t *testing.T) { reqID := uint32(1) chainID := ids.ID{} msg := Message{ - InboundMessage: message.InboundGetAcceptedFrontier(chainID, reqID, 0*time.Second, nodeID, p2p.EngineType_ENGINE_TYPE_SNOWMAN), - EngineType: p2p.EngineType_ENGINE_TYPE_SNOWMAN, + InboundMessage: message.InboundGetAcceptedFrontier(chainID, reqID, 0*time.Second, nodeID), + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } handler.Push(context.Background(), msg) @@ -111,8 +111,8 @@ func TestHandlerDropsTimedOutMessages(t *testing.T) { reqID++ msg = Message{ - InboundMessage: message.InboundGetAccepted(chainID, reqID, 1*time.Second, nil, nodeID, p2p.EngineType_ENGINE_TYPE_SNOWMAN), - EngineType: p2p.EngineType_ENGINE_TYPE_SNOWMAN, + InboundMessage: message.InboundGetAccepted(chainID, reqID, 1*time.Second, nil, nodeID), + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } handler.Push(context.Background(), msg) @@ -210,7 +210,7 @@ func TestHandlerClosesOnError(t *testing.T) { reqID := uint32(1) deadline := time.Nanosecond msg := Message{ - InboundMessage: message.InboundGetAcceptedFrontier(ids.ID{}, reqID, deadline, nodeID, 0), + InboundMessage: message.InboundGetAcceptedFrontier(ids.ID{}, reqID, deadline, nodeID), EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } handler.Push(context.Background(), msg) @@ -288,8 +288,8 @@ func TestHandlerDropsGossipDuringBootstrapping(t *testing.T) { chainID := ids.Empty reqID := uint32(1) inInboundMessage := Message{ - InboundMessage: message.InternalGetFailed(nodeID, chainID, reqID, p2p.EngineType_ENGINE_TYPE_SNOWMAN), - EngineType: p2p.EngineType_ENGINE_TYPE_SNOWMAN, + InboundMessage: message.InternalGetFailed(nodeID, chainID, reqID), + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } handler.Push(context.Background(), inInboundMessage) diff --git a/snow/networking/handler/message_queue_test.go b/snow/networking/handler/message_queue_test.go index 69fbaf531d32..72da75f2d857 100644 --- a/snow/networking/handler/message_queue_test.go +++ b/snow/networking/handler/message_queue_test.go @@ -19,8 +19,6 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" ) -const engineType = p2p.EngineType_ENGINE_TYPE_SNOWMAN - func TestQueue(t *testing.T) { ctrl := gomock.NewController(t) require := require.New(t) @@ -45,9 +43,8 @@ func TestQueue(t *testing.T) { ids.GenerateTestID(), 0, vdr1ID, - engineType, ), - EngineType: engineType, + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } // Push then pop should work regardless of usage when there are no other @@ -105,9 +102,8 @@ func TestQueue(t *testing.T) { ids.GenerateTestID(), 0, vdr2ID, - engineType, ), - EngineType: engineType, + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } // Push msg2 from vdr2ID @@ -132,12 +128,12 @@ func TestQueue(t *testing.T) { // Non-validators should be able to put messages onto [u] nonVdrNodeID1, nonVdrNodeID2 := ids.GenerateTestNodeID(), ids.GenerateTestNodeID() msg3 := Message{ - InboundMessage: message.InboundPullQuery(ids.Empty, 0, 0, ids.Empty, 0, nonVdrNodeID1, engineType), - EngineType: engineType, + InboundMessage: message.InboundPullQuery(ids.Empty, 0, 0, ids.Empty, 0, nonVdrNodeID1), + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } msg4 := Message{ - InboundMessage: message.InboundPushQuery(ids.Empty, 0, 0, nil, 0, nonVdrNodeID2, engineType), - EngineType: engineType, + InboundMessage: message.InboundPushQuery(ids.Empty, 0, 0, nil, 0, nonVdrNodeID2), + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } u.Push(context.Background(), msg3) u.Push(context.Background(), msg4) diff --git a/snow/networking/router/chain_router_test.go b/snow/networking/router/chain_router_test.go index e9617d7ae687..43ccfa09dbf3 100644 --- a/snow/networking/router/chain_router_test.go +++ b/snow/networking/router/chain_router_test.go @@ -304,8 +304,8 @@ func TestShutdownTimesOut(t *testing.T) { go func() { chainID := ids.ID{} msg := handler.Message{ - InboundMessage: message.InboundPullQuery(chainID, 1, time.Hour, ids.GenerateTestID(), 0, nodeID, engineType), - EngineType: engineType, + InboundMessage: message.InboundPullQuery(chainID, 1, time.Hour, ids.GenerateTestID(), 0, nodeID), + EngineType: p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, } h.Push(context.Background(), msg) @@ -541,7 +541,6 @@ func TestRouterTimeout(t *testing.T) { nodeID, ctx.ChainID, requestID, - p2p.EngineType_ENGINE_TYPE_SNOWMAN, ), p2p.EngineType_ENGINE_TYPE_SNOWMAN, ) @@ -561,7 +560,6 @@ func TestRouterTimeout(t *testing.T) { nodeID, ctx.ChainID, requestID, - p2p.EngineType_ENGINE_TYPE_SNOWMAN, ), p2p.EngineType_ENGINE_TYPE_SNOWMAN, ) @@ -601,7 +599,6 @@ func TestRouterTimeout(t *testing.T) { nodeID, ctx.ChainID, requestID, - p2p.EngineType_ENGINE_TYPE_SNOWMAN, ), p2p.EngineType_ENGINE_TYPE_SNOWMAN, ) @@ -621,7 +618,6 @@ func TestRouterTimeout(t *testing.T) { nodeID, ctx.ChainID, requestID, - p2p.EngineType_ENGINE_TYPE_SNOWMAN, ), p2p.EngineType_ENGINE_TYPE_SNOWMAN, ) @@ -799,8 +795,6 @@ func TestRouterHonorsRequestedEngine(t *testing.T) { } { - engineType := p2p.EngineType(100) - requestID++ msg := message.InboundPushQuery( ctx.ChainID, @@ -809,11 +803,10 @@ func TestRouterHonorsRequestedEngine(t *testing.T) { nil, 0, nodeID, - engineType, ) h.EXPECT().Push(gomock.Any(), gomock.Any()).Do(func(_ context.Context, msg handler.Message) { - require.Equal(engineType, msg.EngineType) + require.Equal(p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, msg.EngineType) }) chainRouter.HandleInbound(context.Background(), msg) } @@ -846,19 +839,19 @@ func TestRouterClearTimeouts(t *testing.T) { name: "AcceptedFrontierOp", responseOp: message.AcceptedFrontierOp, responseMsg: message.InboundAcceptedFrontier(ids.Empty, requestID, ids.GenerateTestID(), ids.EmptyNodeID), - timeoutMsg: message.InternalGetAcceptedFrontierFailed(ids.EmptyNodeID, ids.Empty, requestID, engineType), + timeoutMsg: message.InternalGetAcceptedFrontierFailed(ids.EmptyNodeID, ids.Empty, requestID), }, { name: "Accepted", responseOp: message.AcceptedOp, responseMsg: message.InboundAccepted(ids.Empty, requestID, []ids.ID{ids.GenerateTestID()}, ids.EmptyNodeID), - timeoutMsg: message.InternalGetAcceptedFailed(ids.EmptyNodeID, ids.Empty, requestID, engineType), + timeoutMsg: message.InternalGetAcceptedFailed(ids.EmptyNodeID, ids.Empty, requestID), }, { name: "Chits", responseOp: message.ChitsOp, responseMsg: message.InboundChits(ids.Empty, requestID, ids.GenerateTestID(), ids.GenerateTestID(), ids.GenerateTestID(), ids.EmptyNodeID), - timeoutMsg: message.InternalQueryFailed(ids.EmptyNodeID, ids.Empty, requestID, engineType), + timeoutMsg: message.InternalQueryFailed(ids.EmptyNodeID, ids.Empty, requestID), }, { name: "AppResponse", @@ -1037,7 +1030,6 @@ func TestValidatorOnlyMessageDrops(t *testing.T) { dummyContainerID, 0, nID, - p2p.EngineType_ENGINE_TYPE_SNOWMAN, ) chainRouter.HandleInbound(context.Background(), inMsg) @@ -1053,7 +1045,6 @@ func TestValidatorOnlyMessageDrops(t *testing.T) { dummyContainerID, 0, vID, - p2p.EngineType_ENGINE_TYPE_SNOWMAN, ) wg.Add(1) chainRouter.HandleInbound(context.Background(), inMsg) @@ -1305,7 +1296,6 @@ func TestValidatorOnlyAllowedNodeMessageDrops(t *testing.T) { dummyContainerID, 0, nID, - engineType, ) chainRouter.HandleInbound(context.Background(), inMsg) @@ -1321,7 +1311,6 @@ func TestValidatorOnlyAllowedNodeMessageDrops(t *testing.T) { dummyContainerID, 0, allowedID, - engineType, ) wg.Add(1) chainRouter.HandleInbound(context.Background(), inMsg) @@ -1339,7 +1328,6 @@ func TestValidatorOnlyAllowedNodeMessageDrops(t *testing.T) { dummyContainerID, 0, vID, - engineType, ) wg.Add(1) chainRouter.HandleInbound(context.Background(), inMsg) diff --git a/snow/networking/sender/sender.go b/snow/networking/sender/sender.go index b7fa9bd395d3..6bbf22a4ccfb 100644 --- a/snow/networking/sender/sender.go +++ b/snow/networking/sender/sender.go @@ -390,7 +390,6 @@ func (s *sender) SendGetAcceptedFrontier(ctx context.Context, nodeIDs set.Set[id nodeID, s.ctx.ChainID, requestID, - s.engineType, ) s.router.RegisterRequest( ctx, @@ -400,7 +399,7 @@ func (s *sender) SendGetAcceptedFrontier(ctx context.Context, nodeIDs set.Set[id requestID, message.AcceptedFrontierOp, inMsg, - s.engineType, + p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, ) } @@ -413,7 +412,6 @@ func (s *sender) SendGetAcceptedFrontier(ctx context.Context, nodeIDs set.Set[id requestID, deadline, s.ctx.NodeID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -423,7 +421,6 @@ func (s *sender) SendGetAcceptedFrontier(ctx context.Context, nodeIDs set.Set[id s.ctx.ChainID, requestID, deadline, - s.engineType, ) // Send the message over the network. @@ -529,7 +526,6 @@ func (s *sender) SendGetAccepted(ctx context.Context, nodeIDs set.Set[ids.NodeID nodeID, s.ctx.ChainID, requestID, - s.engineType, ) s.router.RegisterRequest( ctx, @@ -539,7 +535,7 @@ func (s *sender) SendGetAccepted(ctx context.Context, nodeIDs set.Set[ids.NodeID requestID, message.AcceptedOp, inMsg, - s.engineType, + p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, ) } @@ -553,7 +549,6 @@ func (s *sender) SendGetAccepted(ctx context.Context, nodeIDs set.Set[ids.NodeID deadline, containerIDs, s.ctx.NodeID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -564,7 +559,6 @@ func (s *sender) SendGetAccepted(ctx context.Context, nodeIDs set.Set[ids.NodeID requestID, deadline, containerIDs, - s.engineType, ) // Send the message over the network. @@ -778,7 +772,6 @@ func (s *sender) SendGet(ctx context.Context, nodeID ids.NodeID, requestID uint3 nodeID, s.ctx.ChainID, requestID, - s.engineType, ) s.router.RegisterRequest( ctx, @@ -788,7 +781,7 @@ func (s *sender) SendGet(ctx context.Context, nodeID ids.NodeID, requestID uint3 requestID, message.PutOp, inMsg, - s.engineType, + p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, ) // Sending a Get to myself always fails. @@ -815,7 +808,6 @@ func (s *sender) SendGet(ctx context.Context, nodeID ids.NodeID, requestID uint3 requestID, deadline, containerID, - s.engineType, ) // Send the message over the network. @@ -857,7 +849,7 @@ func (s *sender) SendGet(ctx context.Context, nodeID ids.NodeID, requestID uint3 func (s *sender) SendPut(_ context.Context, nodeID ids.NodeID, requestID uint32, container []byte) { // Create the outbound message. - outMsg, err := s.msgCreator.Put(s.ctx.ChainID, requestID, container, s.engineType) + outMsg, err := s.msgCreator.Put(s.ctx.ChainID, requestID, container) if err != nil { s.ctx.Log.Error("failed to build message", zap.Stringer("messageOp", message.PutOp), @@ -918,7 +910,6 @@ func (s *sender) SendPushQuery( nodeID, s.ctx.ChainID, requestID, - s.engineType, ) s.router.RegisterRequest( ctx, @@ -928,7 +919,7 @@ func (s *sender) SendPushQuery( requestID, message.ChitsOp, inMsg, - s.engineType, + p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, ) } @@ -947,7 +938,6 @@ func (s *sender) SendPushQuery( container, requestedHeight, s.ctx.NodeID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -967,7 +957,6 @@ func (s *sender) SendPushQuery( nodeID, s.ctx.ChainID, requestID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -980,7 +969,6 @@ func (s *sender) SendPushQuery( deadline, container, requestedHeight, - s.engineType, ) // Send the message over the network. @@ -1033,7 +1021,6 @@ func (s *sender) SendPushQuery( nodeID, s.ctx.ChainID, requestID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -1059,7 +1046,6 @@ func (s *sender) SendPullQuery( nodeID, s.ctx.ChainID, requestID, - s.engineType, ) s.router.RegisterRequest( ctx, @@ -1069,7 +1055,7 @@ func (s *sender) SendPullQuery( requestID, message.ChitsOp, inMsg, - s.engineType, + p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, ) } @@ -1088,7 +1074,6 @@ func (s *sender) SendPullQuery( containerID, requestedHeight, s.ctx.NodeID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -1107,7 +1092,6 @@ func (s *sender) SendPullQuery( nodeID, s.ctx.ChainID, requestID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } @@ -1120,7 +1104,6 @@ func (s *sender) SendPullQuery( deadline, containerID, requestedHeight, - s.engineType, ) // Send the message over the network. @@ -1163,7 +1146,6 @@ func (s *sender) SendPullQuery( nodeID, s.ctx.ChainID, requestID, - s.engineType, ) go s.router.HandleInbound(ctx, inMsg) } diff --git a/snow/networking/sender/sender_test.go b/snow/networking/sender/sender_test.go index d48d347176df..f1ef03e4c5c2 100644 --- a/snow/networking/sender/sender_test.go +++ b/snow/networking/sender/sender_test.go @@ -605,7 +605,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { requestID = uint32(1337) heights = []uint64{1, 2, 3} containerIDs = []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} - engineType = p2p.EngineType_ENGINE_TYPE_SNOWMAN ) snowCtx := snowtest.Context(t, snowtest.PChainID) ctx := snowtest.ConsensusContext(snowCtx) @@ -618,7 +617,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { setMsgCreatorExpect func(msgCreator *message.MockOutboundMsgBuilder) setExternalSenderExpect func(externalSender *MockExternalSender) sendF func(require *require.Assertions, sender common.Sender, nodeIDs set.Set[ids.NodeID]) - engineType p2p.EngineType } tests := []test{ @@ -713,7 +711,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { nodeID, ctx.ChainID, requestID, - engineType, ) }, assertMsgToMyself: func(require *require.Assertions, msg message.InboundMessage) { @@ -722,7 +719,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { require.Equal(ctx.ChainID[:], innerMsg.ChainId) require.Equal(requestID, innerMsg.RequestId) require.Equal(uint64(deadline), innerMsg.Deadline) - require.Equal(engineType, innerMsg.EngineType) }, expectedResponseOp: message.AcceptedFrontierOp, setMsgCreatorExpect: func(msgCreator *message.MockOutboundMsgBuilder) { @@ -730,7 +726,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { ctx.ChainID, requestID, deadline, - engineType, ).Return(nil, nil) }, setExternalSenderExpect: func(externalSender *MockExternalSender) { @@ -747,7 +742,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { sendF: func(_ *require.Assertions, sender common.Sender, nodeIDs set.Set[ids.NodeID]) { sender.SendGetAcceptedFrontier(context.Background(), nodeIDs, requestID) }, - engineType: engineType, }, { name: "GetAccepted", @@ -756,7 +750,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { nodeID, ctx.ChainID, requestID, - engineType, ) }, assertMsgToMyself: func(require *require.Assertions, msg message.InboundMessage) { @@ -765,7 +758,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { require.Equal(ctx.ChainID[:], innerMsg.ChainId) require.Equal(requestID, innerMsg.RequestId) require.Equal(uint64(deadline), innerMsg.Deadline) - require.Equal(engineType, innerMsg.EngineType) }, expectedResponseOp: message.AcceptedOp, setMsgCreatorExpect: func(msgCreator *message.MockOutboundMsgBuilder) { @@ -774,7 +766,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { requestID, deadline, containerIDs, - engineType, ).Return(nil, nil) }, setExternalSenderExpect: func(externalSender *MockExternalSender) { @@ -791,7 +782,6 @@ func TestSender_Bootstrap_Requests(t *testing.T) { sendF: func(_ *require.Assertions, sender common.Sender, nodeIDs set.Set[ids.NodeID]) { sender.SendGetAccepted(context.Background(), nodeIDs, requestID, containerIDs) }, - engineType: engineType, }, } @@ -820,7 +810,7 @@ func TestSender_Bootstrap_Requests(t *testing.T) { externalSender, router, timeoutManager, - engineType, + p2p.EngineType_ENGINE_TYPE_SNOWMAN, subnets.New(ctx.NodeID, subnets.Config{}), ) require.NoError(err) @@ -839,7 +829,7 @@ func TestSender_Bootstrap_Requests(t *testing.T) { requestID, // Request ID tt.expectedResponseOp, // Operation expectedFailedMsg, // Failure Message - tt.engineType, + p2p.EngineType_ENGINE_TYPE_UNSPECIFIED, ) } @@ -877,7 +867,6 @@ func TestSender_Bootstrap_Responses(t *testing.T) { requestID = uint32(1337) summaryIDs = []ids.ID{ids.GenerateTestID(), ids.GenerateTestID()} summary = []byte{1, 2, 3} - engineType = p2p.EngineType_ENGINE_TYPE_AVALANCHE ) snowCtx := snowtest.Context(t, snowtest.PChainID) ctx := snowtest.ConsensusContext(snowCtx) @@ -1040,7 +1029,7 @@ func TestSender_Bootstrap_Responses(t *testing.T) { externalSender, router, timeoutManager, - engineType, + p2p.EngineType_ENGINE_TYPE_SNOWMAN, subnets.New(ctx.NodeID, subnets.Config{}), ) require.NoError(err) @@ -1095,6 +1084,7 @@ func TestSender_Single_Request(t *testing.T) { setMsgCreatorExpect func(msgCreator *message.MockOutboundMsgBuilder) setExternalSenderExpect func(externalSender *MockExternalSender, sentTo set.Set[ids.NodeID]) sendF func(require *require.Assertions, sender common.Sender, nodeID ids.NodeID) + expectedEngineType p2p.EngineType } tests := []test{ @@ -1138,6 +1128,7 @@ func TestSender_Single_Request(t *testing.T) { sendF: func(_ *require.Assertions, sender common.Sender, nodeID ids.NodeID) { sender.SendGetAncestors(context.Background(), nodeID, requestID, containerID) }, + expectedEngineType: engineType, }, { name: "Get", @@ -1146,7 +1137,6 @@ func TestSender_Single_Request(t *testing.T) { nodeID, ctx.ChainID, requestID, - engineType, ) }, assertMsgToMyself: func(require *require.Assertions, msg message.InboundMessage) { @@ -1154,7 +1144,6 @@ func TestSender_Single_Request(t *testing.T) { innerMsg := msg.Message().(*message.GetFailed) require.Equal(ctx.ChainID, innerMsg.ChainID) require.Equal(requestID, innerMsg.RequestID) - require.Equal(engineType, innerMsg.EngineType) }, expectedResponseOp: message.PutOp, setMsgCreatorExpect: func(msgCreator *message.MockOutboundMsgBuilder) { @@ -1163,7 +1152,6 @@ func TestSender_Single_Request(t *testing.T) { requestID, deadline, containerID, - engineType, ).Return(nil, nil) }, setExternalSenderExpect: func(externalSender *MockExternalSender, sentTo set.Set[ids.NodeID]) { @@ -1224,7 +1212,7 @@ func TestSender_Single_Request(t *testing.T) { requestID, // Request ID tt.expectedResponseOp, // Operation expectedFailedMsg, // Failure Message - engineType, // Engine Type + tt.expectedEngineType, // Engine Type ) // Note that HandleInbound is called in a separate goroutine @@ -1260,7 +1248,7 @@ func TestSender_Single_Request(t *testing.T) { requestID, // Request ID tt.expectedResponseOp, // Operation expectedFailedMsg, // Failure Message - engineType, // Engine Type + tt.expectedEngineType, // Engine Type ) // Note that HandleInbound is called in a separate goroutine @@ -1296,7 +1284,7 @@ func TestSender_Single_Request(t *testing.T) { requestID, // Request ID tt.expectedResponseOp, // Operation expectedFailedMsg, // Failure Message - engineType, // Engine Type + tt.expectedEngineType, // Engine Type ) // Note that HandleInbound is called in a separate goroutine From ddf66eaed1659c2caa8531bbda83b360ca85900e Mon Sep 17 00:00:00 2001 From: Alberto Benegiamo Date: Tue, 12 Mar 2024 00:31:13 +0100 Subject: [PATCH 4/4] P-chain: Improve GetValidatorsSet error expressivity (#2808) Co-authored-by: Stephen Buttolph --- vms/platformvm/validators/manager.go | 22 ++++++++++++++++++---- vms/platformvm/warp/validator.go | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/vms/platformvm/validators/manager.go b/vms/platformvm/validators/manager.go index 2c8b025a128b..781d119e226b 100644 --- a/vms/platformvm/validators/manager.go +++ b/vms/platformvm/validators/manager.go @@ -5,11 +5,11 @@ package validators import ( "context" + "errors" "fmt" "time" "github.com/ava-labs/avalanchego/cache" - "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" @@ -30,7 +30,11 @@ const ( recentlyAcceptedWindowTTL = 2 * time.Minute ) -var _ validators.State = (*manager)(nil) +var ( + _ validators.State = (*manager)(nil) + + errUnfinalizedHeight = errors.New("failed to fetch validator set at unfinalized height") +) // Manager adds the ability to introduce newly accepted blocks IDs to the State // interface. @@ -247,7 +251,12 @@ func (m *manager) makePrimaryNetworkValidatorSet( return nil, 0, err } if currentHeight < targetHeight { - return nil, 0, database.ErrNotFound + return nil, 0, fmt.Errorf("%w with SubnetID = %s: current P-chain height (%d) < requested P-Chain height (%d)", + errUnfinalizedHeight, + constants.PrimaryNetworkID, + currentHeight, + targetHeight, + ) } // Rebuild primary network validators at [targetHeight] @@ -295,7 +304,12 @@ func (m *manager) makeSubnetValidatorSet( return nil, 0, err } if currentHeight < targetHeight { - return nil, 0, database.ErrNotFound + return nil, 0, fmt.Errorf("%w with SubnetID = %s: current P-chain height (%d) < requested P-Chain height (%d)", + errUnfinalizedHeight, + subnetID, + currentHeight, + targetHeight, + ) } // Rebuild subnet validators at [targetHeight] diff --git a/vms/platformvm/warp/validator.go b/vms/platformvm/warp/validator.go index d2582927d183..a74c140e9ecd 100644 --- a/vms/platformvm/warp/validator.go +++ b/vms/platformvm/warp/validator.go @@ -55,7 +55,7 @@ func GetCanonicalValidatorSet( // Get the validator set at the given height. vdrSet, err := pChainState.GetValidatorSet(ctx, pChainHeight, subnetID) if err != nil { - return nil, 0, fmt.Errorf("failed to fetch validator set (P-Chain Height: %d, SubnetID: %s): %w", pChainHeight, subnetID, err) + return nil, 0, err } var (