Skip to content

Commit

Permalink
Separate codec registries by upgrade (#3353)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Sep 3, 2024
1 parent 9b03425 commit 9cbcc7c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
27 changes: 17 additions & 10 deletions vms/platformvm/block/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@ func init() {
errs := wrappers.Errs{}
for _, c := range []linearcodec.Codec{c, gc} {
errs.Add(
RegisterApricotBlockTypes(c),
txs.RegisterUnsignedTxsTypes(c),
RegisterBanffBlockTypes(c),
txs.RegisterDurangoUnsignedTxsTypes(c),
RegisterApricotTypes(c),
RegisterBanffTypes(c),
RegisterDurangoTypes(c),
)
}

Expand All @@ -50,25 +49,33 @@ func init() {
}
}

// RegisterApricotBlockTypes allows registering relevant type of blocks package
// in the right sequence. Following repackaging of platformvm package, a few
// subpackage-level codecs were introduced, each handling serialization of
// specific types.
func RegisterApricotBlockTypes(targetCodec codec.Registry) error {
// RegisterApricotTypes registers the type information for blocks that were
// valid during the Apricot series of upgrades.
func RegisterApricotTypes(targetCodec linearcodec.Codec) error {
return errors.Join(
targetCodec.RegisterType(&ApricotProposalBlock{}),
targetCodec.RegisterType(&ApricotAbortBlock{}),
targetCodec.RegisterType(&ApricotCommitBlock{}),
targetCodec.RegisterType(&ApricotStandardBlock{}),
targetCodec.RegisterType(&ApricotAtomicBlock{}),
txs.RegisterApricotTypes(targetCodec),
)
}

func RegisterBanffBlockTypes(targetCodec codec.Registry) error {
// RegisterBanffTypes registers the type information for blocks that were valid
// during the Banff series of upgrades.
func RegisterBanffTypes(targetCodec linearcodec.Codec) error {
return errors.Join(
txs.RegisterBanffTypes(targetCodec),
targetCodec.RegisterType(&BanffProposalBlock{}),
targetCodec.RegisterType(&BanffAbortBlock{}),
targetCodec.RegisterType(&BanffCommitBlock{}),
targetCodec.RegisterType(&BanffStandardBlock{}),
)
}

// RegisterDurangoTypes registers the type information for blocks that were
// valid during the Durango series of upgrades.
func RegisterDurangoTypes(targetCodec linearcodec.Codec) error {
return txs.RegisterDurangoTypes(targetCodec)
}
31 changes: 18 additions & 13 deletions vms/platformvm/txs/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ func init() {
// we skip positions for the blocks.
c.SkipRegistrations(5)

errs.Add(RegisterUnsignedTxsTypes(c))
errs.Add(
RegisterApricotTypes(c),
RegisterBanffTypes(c),
)

c.SkipRegistrations(4)

errs.Add(RegisterDurangoUnsignedTxsTypes(c))
errs.Add(RegisterDurangoTypes(c))
}

Codec = codec.NewDefaultManager()
Expand All @@ -56,14 +59,9 @@ func init() {
}
}

// RegisterUnsignedTxsTypes allows registering relevant type of unsigned package
// in the right sequence. Following repackaging of platformvm package, a few
// subpackage-level codecs were introduced, each handling serialization of
// specific types.
//
// RegisterUnsignedTxsTypes is made exportable so to guarantee that other codecs
// are coherent with components one.
func RegisterUnsignedTxsTypes(targetCodec linearcodec.Codec) error {
// RegisterApricotTypes registers the type information for transactions that
// were valid during the Apricot series of upgrades.
func RegisterApricotTypes(targetCodec linearcodec.Codec) error {
errs := wrappers.Errs{}

// The secp256k1fx is registered here because this is the same place it is
Expand All @@ -90,8 +88,14 @@ func RegisterUnsignedTxsTypes(targetCodec linearcodec.Codec) error {

targetCodec.RegisterType(&stakeable.LockIn{}),
targetCodec.RegisterType(&stakeable.LockOut{}),
)
return errs.Err
}

// Banff additions:
// RegisterBanffTypes registers the type information for transactions that were
// valid during the Banff series of upgrades.
func RegisterBanffTypes(targetCodec linearcodec.Codec) error {
return errors.Join(
targetCodec.RegisterType(&RemoveSubnetValidatorTx{}),
targetCodec.RegisterType(&TransformSubnetTx{}),
targetCodec.RegisterType(&AddPermissionlessValidatorTx{}),
Expand All @@ -100,10 +104,11 @@ func RegisterUnsignedTxsTypes(targetCodec linearcodec.Codec) error {
targetCodec.RegisterType(&signer.Empty{}),
targetCodec.RegisterType(&signer.ProofOfPossession{}),
)
return errs.Err
}

func RegisterDurangoUnsignedTxsTypes(targetCodec linearcodec.Codec) error {
// RegisterDurangoTypes registers the type information for transactions that
// were valid during the Durango series of upgrades.
func RegisterDurangoTypes(targetCodec linearcodec.Codec) error {
return errors.Join(
targetCodec.RegisterType(&TransferSubnetOwnershipTx{}),
targetCodec.RegisterType(&BaseTx{}),
Expand Down

0 comments on commit 9cbcc7c

Please sign in to comment.