From 65210e7fab95ca1eb26510383193966ff7e3ec21 Mon Sep 17 00:00:00 2001 From: Alfonso de la Rocha Date: Mon, 17 Apr 2023 18:49:42 +0200 Subject: [PATCH] update state types --- gateway/cbor_gen.go | 143 +++++++++++++++++++++++++++++++++++- gateway/gateway.go | 1 + gateway/types.go | 5 ++ gen/gen.go | 1 + subnetactor/cbor_gen.go | 40 +--------- subnetactor/subnet-actor.go | 1 - 6 files changed, 148 insertions(+), 43 deletions(-) diff --git a/gateway/cbor_gen.go b/gateway/cbor_gen.go index 565203b..bcb1545 100644 --- a/gateway/cbor_gen.go +++ b/gateway/cbor_gen.go @@ -20,7 +20,7 @@ var _ = cid.Undef var _ = math.E var _ = sort.Sort -var lengthBufState = []byte{140} +var lengthBufState = []byte{141} func (t *State) MarshalCBOR(w io.Writer) error { if t == nil { @@ -111,6 +111,11 @@ func (t *State) MarshalCBOR(w io.Writer) error { if err := t.Validators.MarshalCBOR(cw); err != nil { return err } + + // t.Initialized (bool) (bool) + if err := cbg.WriteBool(w, t.Initialized); err != nil { + return err + } return nil } @@ -133,7 +138,7 @@ func (t *State) UnmarshalCBOR(r io.Reader) (err error) { return fmt.Errorf("cbor input should be of type array") } - if extra != 12 { + if extra != 13 { return fmt.Errorf("cbor input had wrong number of fields") } @@ -301,6 +306,23 @@ func (t *State) UnmarshalCBOR(r io.Reader) (err error) { } } + // t.Initialized (bool) (bool) + + maj, extra, err = cr.ReadHeader() + if err != nil { + return err + } + if maj != cbg.MajOther { + return fmt.Errorf("booleans must be major type 7") + } + switch extra { + case 20: + t.Initialized = false + case 21: + t.Initialized = true + default: + return fmt.Errorf("booleans are either major type 7, value 20 or 21 (got %d)", extra) + } return nil } @@ -1172,7 +1194,7 @@ func (t *StorableMsg) UnmarshalCBOR(r io.Reader) (err error) { return nil } -var lengthBufSubnet = []byte{136} +var lengthBufSubnet = []byte{137} func (t *Subnet) MarshalCBOR(w io.Writer) error { if t == nil { @@ -1235,6 +1257,16 @@ func (t *Subnet) MarshalCBOR(w io.Writer) error { return err } + // t.GenesisEpoch (abi.ChainEpoch) (int64) + if t.GenesisEpoch >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.GenesisEpoch)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.GenesisEpoch-1)); err != nil { + return err + } + } return nil } @@ -1257,7 +1289,7 @@ func (t *Subnet) UnmarshalCBOR(r io.Reader) (err error) { return fmt.Errorf("cbor input should be of type array") } - if extra != 8 { + if extra != 9 { return fmt.Errorf("cbor input had wrong number of fields") } @@ -1372,6 +1404,31 @@ func (t *Subnet) UnmarshalCBOR(r io.Reader) (err error) { t.AppliedBottomupNonce = uint64(extra) } + // t.GenesisEpoch (abi.ChainEpoch) (int64) + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.GenesisEpoch = abi.ChainEpoch(extraI) + } return nil } @@ -1509,6 +1566,84 @@ func (t *FundParams) UnmarshalCBOR(r io.Reader) (err error) { return nil } +var lengthBufInitGenesisEpochParams = []byte{129} + +func (t *InitGenesisEpochParams) MarshalCBOR(w io.Writer) error { + if t == nil { + _, err := w.Write(cbg.CborNull) + return err + } + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufInitGenesisEpochParams); err != nil { + return err + } + + // t.GenesisEpoch (abi.ChainEpoch) (int64) + if t.GenesisEpoch >= 0 { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.GenesisEpoch)); err != nil { + return err + } + } else { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.GenesisEpoch-1)); err != nil { + return err + } + } + return nil +} + +func (t *InitGenesisEpochParams) UnmarshalCBOR(r io.Reader) (err error) { + *t = InitGenesisEpochParams{} + + cr := cbg.NewCborReader(r) + + maj, extra, err := cr.ReadHeader() + if err != nil { + return err + } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + + if maj != cbg.MajArray { + return fmt.Errorf("cbor input should be of type array") + } + + if extra != 1 { + return fmt.Errorf("cbor input had wrong number of fields") + } + + // t.GenesisEpoch (abi.ChainEpoch) (int64) + { + maj, extra, err := cr.ReadHeader() + var extraI int64 + if err != nil { + return err + } + switch maj { + case cbg.MajUnsignedInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 positive overflow") + } + case cbg.MajNegativeInt: + extraI = int64(extra) + if extraI < 0 { + return fmt.Errorf("int64 negative oveflow") + } + extraI = -1 - extraI + default: + return fmt.Errorf("wrong type for int64 field: %d", maj) + } + + t.GenesisEpoch = abi.ChainEpoch(extraI) + } + return nil +} + var lengthBufCrossMsgParams = []byte{130} func (t *CrossMsgParams) MarshalCBOR(w io.Writer) error { diff --git a/gateway/gateway.go b/gateway/gateway.go index 0279353..c167eda 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -27,6 +27,7 @@ type State struct { AppliedTopdownNonce uint64 TopDownCheckpointVoting voting.Voting Validators validator.OnChainValidators + Initialized bool } func (st *State) GetSubnet(s adt.Store, id sdk.SubnetID) (*Subnet, bool, error) { diff --git a/gateway/types.go b/gateway/types.go index 12f9570..3983af7 100644 --- a/gateway/types.go +++ b/gateway/types.go @@ -28,6 +28,7 @@ type Subnet struct { Status sdk.Status PrevCheckpoint *BottomUpCheckpoint AppliedBottomupNonce uint64 + GenesisEpoch abi.ChainEpoch } func (sn *Subnet) GetTopDownMsg(s adt.Store, nonce uint64) (*CrossMsg, bool, error) { @@ -114,6 +115,10 @@ type CrossMsgParams struct { Destination sdk.SubnetID } +type InitGenesisEpochParams struct { + GenesisEpoch abi.ChainEpoch +} + type CrossMsgs struct { Msgs []CrossMsg } diff --git a/gen/gen.go b/gen/gen.go index 72b9dbd..90ad192 100644 --- a/gen/gen.go +++ b/gen/gen.go @@ -24,6 +24,7 @@ func main() { gateway.Subnet{}, gateway.CrossMsg{}, gateway.FundParams{}, + gateway.InitGenesisEpochParams{}, gateway.CrossMsgParams{}, gateway.CrossMsgs{}, ); err != nil { diff --git a/subnetactor/cbor_gen.go b/subnetactor/cbor_gen.go index f0a10dc..3a99b3f 100644 --- a/subnetactor/cbor_gen.go +++ b/subnetactor/cbor_gen.go @@ -22,7 +22,7 @@ var _ = cid.Undef var _ = math.E var _ = sort.Sort -var lengthBufState = []byte{145} +var lengthBufState = []byte{144} func (t *State) MarshalCBOR(w io.Writer) error { if t == nil { @@ -126,17 +126,6 @@ func (t *State) MarshalCBOR(w io.Writer) error { } } - // t.GenesisEpoch (abi.ChainEpoch) (int64) - if t.GenesisEpoch >= 0 { - if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.GenesisEpoch)); err != nil { - return err - } - } else { - if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.GenesisEpoch-1)); err != nil { - return err - } - } - // t.CommittedCheckpoints (cid.Cid) (struct) if err := cbg.WriteCid(cw, t.CommittedCheckpoints); err != nil { @@ -186,7 +175,7 @@ func (t *State) UnmarshalCBOR(r io.Reader) (err error) { return fmt.Errorf("cbor input should be of type array") } - if extra != 17 { + if extra != 16 { return fmt.Errorf("cbor input had wrong number of fields") } @@ -358,31 +347,6 @@ func (t *State) UnmarshalCBOR(r io.Reader) (err error) { t.TopDownCheckPeriod = abi.ChainEpoch(extraI) } - // t.GenesisEpoch (abi.ChainEpoch) (int64) - { - maj, extra, err := cr.ReadHeader() - var extraI int64 - if err != nil { - return err - } - switch maj { - case cbg.MajUnsignedInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 positive overflow") - } - case cbg.MajNegativeInt: - extraI = int64(extra) - if extraI < 0 { - return fmt.Errorf("int64 negative oveflow") - } - extraI = -1 - extraI - default: - return fmt.Errorf("wrong type for int64 field: %d", maj) - } - - t.GenesisEpoch = abi.ChainEpoch(extraI) - } // t.CommittedCheckpoints (cid.Cid) (struct) { diff --git a/subnetactor/subnet-actor.go b/subnetactor/subnet-actor.go index c4b12f6..53b5a56 100644 --- a/subnetactor/subnet-actor.go +++ b/subnetactor/subnet-actor.go @@ -29,7 +29,6 @@ type State struct { Genesis []byte BottomUpCheckPeriod abi.ChainEpoch TopDownCheckPeriod abi.ChainEpoch - GenesisEpoch abi.ChainEpoch CommittedCheckpoints cid.Cid // TCid> ValidatorSet *validator.Set MinValidators uint64