From 62b4804cc3f2fcd47bbca67ee214d2a2b25f0e9c Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Wed, 18 Dec 2024 12:39:31 -0500 Subject: [PATCH 1/4] rollup registry to record valid rollups --- actions/errors.go | 1 + actions/rollup_register.go | 38 ++++++++++--------------- controller/controller.go | 16 +++++++++-- controller/resolutions.go | 5 ++++ go.mod | 2 +- rollup_registry/registry.go | 57 +++++++++++++++++++++++++++++++++++++ rpc/dependencies.go | 2 ++ rpc/jsonrpc_client.go | 11 +++++++ rpc/jsonrpc_server.go | 6 ++++ tests/e2e/e2e_test.go | 2 +- types/types.go | 8 ++++++ 11 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 rollup_registry/registry.go diff --git a/actions/errors.go b/actions/errors.go index 3dd2c6b..c945115 100644 --- a/actions/errors.go +++ b/actions/errors.go @@ -14,4 +14,5 @@ var ( ErrNameSpaceNotRegistered = errors.New("namespace not registered") ErrNotAuthorized = errors.New("not authorized") ErrNameSpaceAlreadyRegistered = errors.New("namespace already registered") + ErrExitEpochSmallerThanStartEpoch = errors.New("exit epoch is smaller than start epoch") ) diff --git a/actions/rollup_register.go b/actions/rollup_register.go index 652cffc..a1ef6f2 100644 --- a/actions/rollup_register.go +++ b/actions/rollup_register.go @@ -5,7 +5,6 @@ import ( "context" "encoding/hex" "fmt" - "slices" hactions "github.com/AnomalyFi/hypersdk/actions" "github.com/AnomalyFi/hypersdk/chain" @@ -20,7 +19,7 @@ var _ chain.Action = (*RollupRegistration)(nil) const ( CreateRollup = iota - DeleteRollup + ExitRollup UpdateRollup ) @@ -45,6 +44,8 @@ func (*RollupRegistration) StateKeysMaxChunks() []uint16 { return []uint16{hactions.RollupInfoChunks, hactions.RollupRegistryChunks} } +// TODO: this action needs to be managed by DAO to manage deletions since we are not deleting any namespace from storage +// but only by marking them as regsitered or exited func (r *RollupRegistration) Execute( ctx context.Context, rules chain.Rules, @@ -69,17 +70,18 @@ func (r *RollupRegistration) Execute( switch r.OpCode { case CreateRollup: - if r.Info.StartEpoch < Epoch(hght, rules.GetEpochLength())+2 { - return nil, fmt.Errorf("epoch number is not valid, minimum: %d, actual: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.StartEpoch) - } if contains(namespaces, r.Namespace) { return nil, ErrNameSpaceAlreadyRegistered } + if r.Info.StartEpoch < Epoch(hght, rules.GetEpochLength())+2 || r.Info.ExitEpoch != 0 { + return nil, fmt.Errorf("epoch number is not valid, minimum: %d, actual: %d, exit: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.StartEpoch, r.Info.ExitEpoch) + } namespaces = append(namespaces, r.Namespace) if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(CREATE): %s", err.Error()) } case UpdateRollup: + // only allow modifing informations that are not related to ExitEpoch or StartEpoch if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { return nil, fmt.Errorf("authorization failed(UPDATE): %s", err.Error()) } @@ -88,32 +90,22 @@ func (r *RollupRegistration) Execute( if err != nil { return nil, fmt.Errorf("unable to get existing rollup info(UPDATE): %s", err.Error()) } - if r.Info.StartEpoch != rollupInfoExists.StartEpoch && r.Info.StartEpoch < Epoch(hght, rules.GetEpochLength())+2 { - return nil, fmt.Errorf("(UPDATE)epoch number is not valid, minimum: %d, actual: %d, prev: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.StartEpoch, rollupInfoExists.StartEpoch) + if rollupInfoExists.ExitEpoch != r.Info.ExitEpoch || rollupInfoExists.StartEpoch != r.Info.StartEpoch { + return nil, fmt.Errorf("disallowed tamper for exit epoch & start epoch") } if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(UPDATE): %s", err.Error()) } - case DeleteRollup: + case ExitRollup: if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { - return nil, fmt.Errorf("unable to set rollup info(DELETE): %s", err.Error()) - } - if r.Info.StartEpoch < Epoch(hght, rules.GetEpochLength())+2 { - return nil, fmt.Errorf("(DELETE)epoch number is not valid, minimum: %d, actual: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.StartEpoch) + return nil, fmt.Errorf("unable to set rollup info(EXIT): %s", err.Error()) } - - nsIdx := -1 - for i, ns := range namespaces { - if bytes.Equal(r.Namespace, ns) { - nsIdx = i - break - } + if r.Info.ExitEpoch < Epoch(hght, rules.GetEpochLength())+2 { + return nil, fmt.Errorf("(EXIT)epoch number is not valid, minimum: %d, actual: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.ExitEpoch) } - namespaces = slices.Delete(namespaces, nsIdx, nsIdx+1) - - if err := storage.DelRollupInfo(ctx, mu, r.Namespace); err != nil { - return nil, err + if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { + return nil, fmt.Errorf("unable to set rollup info(EXIT): %s", err.Error()) } default: return nil, fmt.Errorf("op code(%d) not supported", r.OpCode) diff --git a/controller/controller.go b/controller/controller.go index d14d95e..e9e9904 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -8,6 +8,8 @@ import ( "fmt" "net/http" + hactions "github.com/AnomalyFi/hypersdk/actions" + "github.com/AnomalyFi/hypersdk/builder" "github.com/AnomalyFi/hypersdk/chain" "github.com/AnomalyFi/hypersdk/fees" @@ -26,6 +28,7 @@ import ( "github.com/AnomalyFi/nodekit-seq/config" "github.com/AnomalyFi/nodekit-seq/consts" "github.com/AnomalyFi/nodekit-seq/genesis" + rollupregistry "github.com/AnomalyFi/nodekit-seq/rollup_registry" "github.com/AnomalyFi/nodekit-seq/rpc" "github.com/AnomalyFi/nodekit-seq/storage" "github.com/AnomalyFi/nodekit-seq/version" @@ -41,8 +44,9 @@ type Controller struct { config *config.Config stateManager *StateManager - jsonRPCServer *rpc.JSONRPCServer - archiver *archiver.ORMArchiver + jsonRPCServer *rpc.JSONRPCServer + archiver *archiver.ORMArchiver + rollupRegistry *rollupregistry.RollupRegistry metrics *metrics @@ -134,6 +138,8 @@ func (c *Controller) Initialize( return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err } + c.rollupRegistry = rollupregistry.NewRollupRegistr() + apis[rpc.JSONRPCEndpoint] = jsonRPCHandler // Create builder and gossiper @@ -199,6 +205,7 @@ func (c *Controller) Accepted(ctx context.Context, blk *chain.StatelessBlock) er } }() + rollups := make([]*hactions.RollupInfo, 0) results := blk.Results() for i, tx := range blk.Txs { result := results[i] @@ -223,10 +230,15 @@ func (c *Controller) Accepted(ctx context.Context, blk *chain.StatelessBlock) er c.metrics.transfer.Inc() case *actions.SequencerMsg: c.metrics.sequencerMsg.Inc() + case *actions.RollupRegistration: + reg := act.(*actions.RollupRegistration) + rollups = append(rollups, ®.Info) } } } } + currentEpoch := blk.Hght / uint64(c.inner.Rules(blk.Tmstmp).GetEpochLength()) + c.rollupRegistry.Update(currentEpoch, rollups) return batch.Write() } diff --git a/controller/resolutions.go b/controller/resolutions.go index 5d3380c..ab3ed72 100644 --- a/controller/resolutions.go +++ b/controller/resolutions.go @@ -12,6 +12,7 @@ import ( "github.com/AnomalyFi/nodekit-seq/archiver" "github.com/AnomalyFi/nodekit-seq/genesis" + rollupregistry "github.com/AnomalyFi/nodekit-seq/rollup_registry" "github.com/AnomalyFi/nodekit-seq/storage" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/trace" @@ -83,6 +84,10 @@ func (c *Controller) Archiver() *archiver.ORMArchiver { return c.archiver } +func (c *Controller) RollupRegistry() *rollupregistry.RollupRegistry { + return c.rollupRegistry +} + func (c *Controller) NetworkID() uint32 { return c.snowCtx.NetworkID } diff --git a/go.mod b/go.mod index e26bef7..13e216a 100644 --- a/go.mod +++ b/go.mod @@ -173,4 +173,4 @@ require ( // replace github.com/ava-labs/coreth => github.com/AnomalyFi/coreth v0.12.5-rc.6.1 -// replace github.com/AnomalyFi/hypersdk => ../hypersdk +replace github.com/AnomalyFi/hypersdk => ../hypersdk diff --git a/rollup_registry/registry.go b/rollup_registry/registry.go new file mode 100644 index 0000000..84a8c31 --- /dev/null +++ b/rollup_registry/registry.go @@ -0,0 +1,57 @@ +package rollupregistry + +import ( + "slices" + "sync" + + hactions "github.com/AnomalyFi/hypersdk/actions" +) + +type RollupRegistryOnlyRead interface { + RollupsValidAtEpoch(epoch uint64) []*hactions.RollupInfo +} + +type RollupRegistryAllPerm interface { + RollupRegistryOnlyRead + Update(currentEpoch uint64, rollups []*hactions.RollupInfo) +} + +var _ RollupRegistryAllPerm = (*RollupRegistry)(nil) + +type RollupRegistry struct { + rollups []*hactions.RollupInfo + rollupsL sync.RWMutex +} + +func NewRollupRegistr() *RollupRegistry { + return &RollupRegistry{ + rollups: make([]*hactions.RollupInfo, 0), + } +} + +func (r *RollupRegistry) RollupsValidAtEpoch(epoch uint64) []*hactions.RollupInfo { + r.rollupsL.RLock() + defer r.rollupsL.RUnlock() + + ret := make([]*hactions.RollupInfo, 0) + for _, rollup := range r.rollups { + if !rollup.ValidAtEpoch(epoch) { + continue + } + + ret = append(ret, rollup) + } + + return ret +} + +func (r *RollupRegistry) Update(currentEpoch uint64, rollups []*hactions.RollupInfo) { + r.rollupsL.Lock() + defer r.rollupsL.Unlock() + + r.rollups = append(r.rollups, rollups...) + // remove exited rollups + r.rollups = slices.DeleteFunc(r.rollups, func(rollup *hactions.RollupInfo) bool { + return rollup.Exited(currentEpoch) + }) +} diff --git a/rpc/dependencies.go b/rpc/dependencies.go index 63efdef..48f657f 100644 --- a/rpc/dependencies.go +++ b/rpc/dependencies.go @@ -12,6 +12,7 @@ import ( "github.com/AnomalyFi/hypersdk/fees" "github.com/AnomalyFi/nodekit-seq/archiver" "github.com/AnomalyFi/nodekit-seq/genesis" + rollupregistry "github.com/AnomalyFi/nodekit-seq/rollup_registry" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/trace" "github.com/ava-labs/avalanchego/utils/logging" @@ -39,4 +40,5 @@ type Controller interface { Logger() logging.Logger // TODO: update this to only have read permission Archiver() *archiver.ORMArchiver + RollupRegistry() *rollupregistry.RollupRegistry } diff --git a/rpc/jsonrpc_client.go b/rpc/jsonrpc_client.go index 7eebada..13d3f73 100644 --- a/rpc/jsonrpc_client.go +++ b/rpc/jsonrpc_client.go @@ -300,6 +300,17 @@ func (cli *JSONRPCClient) GetAllRollupInfo(ctx context.Context) (*types.GetAllRo return resp, err } +func (cli *JSONRPCClient) GetValidRollupsAtEpoch(ctx context.Context, epoch uint64) (*types.GetRollupsInfoAtEpochReply, error) { + resp := new(types.GetRollupsInfoAtEpochReply) + err := cli.requester.SendRequest( + ctx, + "getValidRollupsAtEpoch", + types.GetRollupsInfoAtEpochArgs{Epoch: epoch}, + resp, + ) + return resp, err +} + func (cli *JSONRPCClient) GetEpochExits(ctx context.Context, epoch uint64) (*hactions.EpochExitInfo, error) { resp := new(types.EpochExitsReply) args := &types.EpochExitsArgs{Epoch: epoch} diff --git a/rpc/jsonrpc_server.go b/rpc/jsonrpc_server.go index fd61ddf..677f197 100644 --- a/rpc/jsonrpc_server.go +++ b/rpc/jsonrpc_server.go @@ -426,6 +426,12 @@ func (j *JSONRPCServer) GetAllRollupInfo(req *http.Request, _ *struct{}, reply * return nil } +func (j *JSONRPCServer) GetValidRollupsAtEpoch(req *http.Request, args *types.GetRollupsInfoAtEpochArgs, reply *types.GetRollupsInfoAtEpochReply) error { + registry := j.c.RollupRegistry() + reply.Rollups = registry.RollupsValidAtEpoch(args.Epoch) + return nil +} + var _ chain.Parser = (*ServerParser)(nil) type ServerParser struct { diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 92bc52e..cf7e8c6 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -1111,7 +1111,7 @@ var _ = ginkgo.Describe("[Test]", func() { StartEpoch: currEpoch + 5, }, Namespace: []byte("nkit2"), - OpCode: actions.DeleteRollup, + OpCode: actions.ExitRollup, }, } diff --git a/types/types.go b/types/types.go index de18f72..42ebabd 100644 --- a/types/types.go +++ b/types/types.go @@ -247,3 +247,11 @@ type GetAllRollupInfoReply struct { // epoch -> a list of rollup registration info Info map[uint64][]hactions.RollupInfo `json:"info"` } + +type GetRollupsInfoAtEpochArgs struct { + Epoch uint64 `json:"epoch"` +} + +type GetRollupsInfoAtEpochReply struct { + Rollups []*hactions.RollupInfo `json:"rollups"` +} From 19fe8c9ee0b33ce5496a65ac5c43b79b4fb45b4f Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Wed, 18 Dec 2024 13:40:57 -0500 Subject: [PATCH 2/4] registry test & fix --- actions/rollup_register.go | 15 +++-- rollup_registry/registry.go | 15 +++-- tests/e2e/e2e_test.go | 129 +++++++++++++++++++++++++++++++++++- 3 files changed, 147 insertions(+), 12 deletions(-) diff --git a/actions/rollup_register.go b/actions/rollup_register.go index a1ef6f2..7c323ae 100644 --- a/actions/rollup_register.go +++ b/actions/rollup_register.go @@ -90,9 +90,10 @@ func (r *RollupRegistration) Execute( if err != nil { return nil, fmt.Errorf("unable to get existing rollup info(UPDATE): %s", err.Error()) } - if rollupInfoExists.ExitEpoch != r.Info.ExitEpoch || rollupInfoExists.StartEpoch != r.Info.StartEpoch { - return nil, fmt.Errorf("disallowed tamper for exit epoch & start epoch") - } + + // rewrite epoch info + r.Info.ExitEpoch = rollupInfoExists.ExitEpoch + r.Info.StartEpoch = rollupInfoExists.StartEpoch if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(UPDATE): %s", err.Error()) @@ -101,8 +102,12 @@ func (r *RollupRegistration) Execute( if err := authorizationChecks(ctx, actor, namespaces, r.Namespace, mu); err != nil { return nil, fmt.Errorf("unable to set rollup info(EXIT): %s", err.Error()) } - if r.Info.ExitEpoch < Epoch(hght, rules.GetEpochLength())+2 { - return nil, fmt.Errorf("(EXIT)epoch number is not valid, minimum: %d, actual: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.ExitEpoch) + rollupInfoExists, err := storage.GetRollupInfo(ctx, mu, r.Namespace) + if err != nil { + return nil, fmt.Errorf("unable to get existing rollup info(UPDATE): %s", err.Error()) + } + if r.Info.ExitEpoch < rollupInfoExists.StartEpoch || r.Info.ExitEpoch < Epoch(hght, rules.GetEpochLength())+2 { + return nil, fmt.Errorf("(EXIT)epoch number is not valid, minimum: %d, actual: %d, start: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.ExitEpoch, rollupInfoExists.StartEpoch) } if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(EXIT): %s", err.Error()) diff --git a/rollup_registry/registry.go b/rollup_registry/registry.go index 84a8c31..0a0e952 100644 --- a/rollup_registry/registry.go +++ b/rollup_registry/registry.go @@ -1,10 +1,11 @@ package rollupregistry import ( - "slices" + "maps" "sync" hactions "github.com/AnomalyFi/hypersdk/actions" + "github.com/ava-labs/avalanchego/ids" ) type RollupRegistryOnlyRead interface { @@ -19,13 +20,13 @@ type RollupRegistryAllPerm interface { var _ RollupRegistryAllPerm = (*RollupRegistry)(nil) type RollupRegistry struct { - rollups []*hactions.RollupInfo + rollups map[ids.ID]*hactions.RollupInfo rollupsL sync.RWMutex } func NewRollupRegistr() *RollupRegistry { return &RollupRegistry{ - rollups: make([]*hactions.RollupInfo, 0), + rollups: make(map[ids.ID]*hactions.RollupInfo), } } @@ -49,9 +50,11 @@ func (r *RollupRegistry) Update(currentEpoch uint64, rollups []*hactions.RollupI r.rollupsL.Lock() defer r.rollupsL.Unlock() - r.rollups = append(r.rollups, rollups...) - // remove exited rollups - r.rollups = slices.DeleteFunc(r.rollups, func(rollup *hactions.RollupInfo) bool { + for _, rollup := range rollups { + r.rollups[rollup.ID()] = rollup + } + + maps.DeleteFunc(r.rollups, func(_ ids.ID, rollup *hactions.RollupInfo) bool { return rollup.Exited(currentEpoch) }) } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index cf7e8c6..c774659 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -1015,6 +1015,133 @@ var _ = ginkgo.Describe("[Test]", func() { pubKeyDummy := make([]byte, 48) pubKeyDummy[1] = 1 + ginkgo.It("test rollup registry can capture rollup registration & exits correctly", func() { + ctx := context.Background() + ctx, cancel := context.WithTimeout(ctx, 20*time.Second) + defer cancel() + _, startHeight, _, err := instances[0].cli.Accepted(ctx) + require.NoError(err) + + // submit regsitration at startHeight + currEpoch, err := instances[0].cli.GetCurrentEpoch() + require.NoError(err) + txActions := []chain.Action{&actions.RollupRegistration{ + Info: hactions.RollupInfo{ + Namespace: []byte("1234"), + FeeRecipient: rsender, + AuthoritySEQAddress: rsender, + SequencerPublicKey: pubKeyDummy, + StartEpoch: currEpoch + 5, + }, + Namespace: []byte("1234"), + OpCode: actions.CreateRollup, + }, &actions.RollupRegistration{ + Info: hactions.RollupInfo{ + Namespace: []byte("1235"), + FeeRecipient: rsender, + AuthoritySEQAddress: rsender, + SequencerPublicKey: pubKeyDummy, + StartEpoch: currEpoch + 5, + }, + Namespace: []byte("1235"), + OpCode: actions.CreateRollup, + }} + parser, err := instances[0].tcli.Parser(ctx) + require.NoError(err) + _, tx, _, err := instances[0].cli.GenerateTransaction(ctx, parser, txActions, factory, 0) + require.NoError(err) + hutils.Outf("{{green}}txID of submitted data:{{/}}%s\n", tx.ID().String()) + + err = instances[0].wsCli.RegisterTx(tx) + require.NoError(err) + txID, txErr, result, err := instances[0].wsCli.ListenTx(ctx) + require.Equal(tx.ID(), txID) + require.NoError(err) + require.NoError(txErr) + require.Empty(string(result.Error)) + require.True(result.Success) + + var h1 = startHeight + // Ensure all blocks processed + for _, inst := range instances { + color.Blue("checking %q", inst.uri) + + // Ensure all blocks processed + for { + _, h, _, err := inst.cli.Accepted(context.Background()) + require.NoError(err) + if h > startHeight { + h1 = h + break + } + time.Sleep(1 * time.Second) + } + } + + validRollupResp, err := instances[0].tcli.GetValidRollupsAtEpoch(ctx, currEpoch+5) + require.NoError(err) + require.Equal(2, len(validRollupResp.Rollups)) + + // submit exits at height h1 + txActions = []chain.Action{&actions.RollupRegistration{ + Info: hactions.RollupInfo{ + Namespace: []byte("1234"), + FeeRecipient: rsender, + AuthoritySEQAddress: rsender, + SequencerPublicKey: pubKeyDummy, + ExitEpoch: currEpoch + 6, + }, + Namespace: []byte("1234"), + OpCode: actions.ExitRollup, + }, &actions.RollupRegistration{ + Info: hactions.RollupInfo{ + Namespace: []byte("1235"), + FeeRecipient: rsender, + AuthoritySEQAddress: rsender, + SequencerPublicKey: pubKeyDummy, + ExitEpoch: currEpoch + 7, + }, + Namespace: []byte("1235"), + OpCode: actions.ExitRollup, + }} + _, tx, _, err = instances[0].cli.GenerateTransaction(ctx, parser, txActions, factory, 0) + require.NoError(err) + hutils.Outf("{{green}}txID of submitted data:{{/}}%s\n", tx.ID().String()) + + err = instances[0].wsCli.RegisterTx(tx) + require.NoError(err) + txID, txErr, result, err = instances[0].wsCli.ListenTx(ctx) + require.Equal(tx.ID(), txID) + require.NoError(err) + require.NoError(txErr) + require.Empty(string(result.Error)) + require.True(result.Success) + + // Ensure all blocks processed + for _, inst := range instances { + color.Blue("checking %q", inst.uri) + + // Ensure all blocks processed + for { + _, h, _, err := inst.cli.Accepted(context.Background()) + require.NoError(err) + if h > h1 { + break + } + time.Sleep(1 * time.Second) + } + } + + validRollupResp, err = instances[0].tcli.GetValidRollupsAtEpoch(ctx, currEpoch+6) + require.NoError(err) + require.Equal(1, len(validRollupResp.Rollups)) + require.Equal([]byte("1235"), validRollupResp.Rollups[0].Namespace) + + validRollupResp, err = instances[0].tcli.GetValidRollupsAtEpoch(ctx, currEpoch+7) + require.NoError(err) + require.Equal(0, len(validRollupResp.Rollups)) + }) + ginkgo.It("test register rollup", func() { ctx := context.Background() ctx, cancel := context.WithTimeout(ctx, 20*time.Second) @@ -1108,7 +1235,7 @@ var _ = ginkgo.Describe("[Test]", func() { FeeRecipient: rsender, AuthoritySEQAddress: rsender, SequencerPublicKey: pubKeyDummy, - StartEpoch: currEpoch + 5, + ExitEpoch: currEpoch + 7, }, Namespace: []byte("nkit2"), OpCode: actions.ExitRollup, From 87b80c50e0fdbb2d42045fd6008b45279356c9ab Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Wed, 18 Dec 2024 13:49:57 -0500 Subject: [PATCH 3/4] go.mod update --- go.mod | 4 ++-- go.sum | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 13e216a..649ad73 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AnomalyFi/nodekit-seq go 1.21.12 require ( - github.com/AnomalyFi/hypersdk v0.9.7-arcadia.12 + github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13 github.com/ava-labs/avalanche-network-runner v1.7.4-rc.0 github.com/ava-labs/avalanchego v1.11.10 github.com/ethereum/go-ethereum v1.13.14 @@ -173,4 +173,4 @@ require ( // replace github.com/ava-labs/coreth => github.com/AnomalyFi/coreth v0.12.5-rc.6.1 -replace github.com/AnomalyFi/hypersdk => ../hypersdk +// replace github.com/AnomalyFi/hypersdk => ../hypersdk diff --git a/go.sum b/go.sum index 5291df0..e3747b3 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.12 h1:X5m2I249t4OMkCa2hAtB0VkDMcSFLtvl0QDBa3GR+AA= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.12/go.mod h1:0Vj2PdwSFN7pat4Sno39IfmtOiv/gO9mxZXyRKnoKtI= +github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13 h1:jZJXZpW6gQkfH0draUp5fQLwCfKzRYhNLHDxz33ncOs= +github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13/go.mod h1:0Vj2PdwSFN7pat4Sno39IfmtOiv/gO9mxZXyRKnoKtI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= From a7ba8af31de74d9e4e63bcdf32c5dc59c25bc466 Mon Sep 17 00:00:00 2001 From: bianyuanop Date: Thu, 19 Dec 2024 12:47:38 -0500 Subject: [PATCH 4/4] custom allocation --- actions/rollup_register.go | 4 ++++ cmd/seq-cli/cmd/action.go | 6 ++++-- go.mod | 2 +- go.sum | 2 -- scripts/run.sh | 6 +++++- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/actions/rollup_register.go b/actions/rollup_register.go index 7c323ae..77db6ab 100644 --- a/actions/rollup_register.go +++ b/actions/rollup_register.go @@ -109,6 +109,10 @@ func (r *RollupRegistration) Execute( if r.Info.ExitEpoch < rollupInfoExists.StartEpoch || r.Info.ExitEpoch < Epoch(hght, rules.GetEpochLength())+2 { return nil, fmt.Errorf("(EXIT)epoch number is not valid, minimum: %d, actual: %d, start: %d", Epoch(hght, rules.GetEpochLength())+2, r.Info.ExitEpoch, rollupInfoExists.StartEpoch) } + + // overwrite StartEpoch + r.Info.StartEpoch = rollupInfoExists.StartEpoch + if err := storage.SetRollupInfo(ctx, mu, r.Namespace, &r.Info); err != nil { return nil, fmt.Errorf("unable to set rollup info(EXIT): %s", err.Error()) } diff --git a/cmd/seq-cli/cmd/action.go b/cmd/seq-cli/cmd/action.go index 10392dd..1c3b6f0 100644 --- a/cmd/seq-cli/cmd/action.go +++ b/cmd/seq-cli/cmd/action.go @@ -123,7 +123,7 @@ var rollupCmd = &cobra.Command{ return err } - op, err := handler.Root().PromptChoice("(0)create (1)delete (2)update", 3) + op, err := handler.Root().PromptChoice("(0)create (1)exit (2)update", 3) if err != nil { return err } @@ -133,7 +133,9 @@ var rollupCmd = &cobra.Command{ FeeRecipient: feeRecipient, Namespace: namespace, AuthoritySEQAddress: feeRecipient, - StartEpoch: e + 4, + SequencerPublicKey: feeRecipient[:], + StartEpoch: e + 10, + ExitEpoch: 0, } // Generate transaction _, err = sendAndWait(ctx, []chain.Action{&actions.RollupRegistration{ diff --git a/go.mod b/go.mod index 649ad73..7027a63 100644 --- a/go.mod +++ b/go.mod @@ -173,4 +173,4 @@ require ( // replace github.com/ava-labs/coreth => github.com/AnomalyFi/coreth v0.12.5-rc.6.1 -// replace github.com/AnomalyFi/hypersdk => ../hypersdk +replace github.com/AnomalyFi/hypersdk => ../hypersdk diff --git a/go.sum b/go.sum index e3747b3..c4e7b93 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13 h1:jZJXZpW6gQkfH0draUp5fQLwCfKzRYhNLHDxz33ncOs= -github.com/AnomalyFi/hypersdk v0.9.7-arcadia.13/go.mod h1:0Vj2PdwSFN7pat4Sno39IfmtOiv/gO9mxZXyRKnoKtI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= diff --git a/scripts/run.sh b/scripts/run.sh index a126ff2..5759366 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -135,9 +135,13 @@ find "${TMPDIR}"/avalanchego-"${VERSION}" # Make sure to replace this address with your own address # if you are starting your own devnet (otherwise anyone can access # funds using the included demo.pk) +# total stake can allocate: 10000000000000000000, make sure it is below this or genesis won't load echo "creating allocations file" cat < "${TMPDIR}"/allocations.json -[{"address":"${ADDRESS}", "balance":10000000000000000000}] +[ + {"address":"${ADDRESS}", "balance":1000000000000000000}, + {"address":"seq1qy94dndd0wzru9gvq3ayw52ngcd2fuhyptt58f4a3eppjzpx573qg9cr7sm", "balance":1000000000000000000} +] EOF GENESIS_PATH=$2