From 90f26e3ffd0c93a3c50a804f170fdcffeeca2717 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 17 Mar 2021 16:58:56 +0300 Subject: [PATCH] [#61] netmap: Invoke clean up methods on new epoch Signed-off-by: Alex Vanin --- netmap/netmap_contract.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index aa3c637..b7f0b7a 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -39,6 +39,10 @@ const ( snapshot0Key = "snapshotCurrent" snapshot1Key = "snapshotPrevious" snapshotEpoch = "snapshotEpoch" + + containerContractKey = "containerScriptHash" + balanceContractKey = "balanceScriptHash" + cleanupEpochMethod = "newEpoch" ) const ( @@ -53,13 +57,17 @@ var ( // Init function sets up initial list of inner ring public keys and should // be invoked once at neofs infrastructure setup. -func Init(owner interop.Hash160, keys []interop.PublicKey) { +func Init(owner, addrBalance, addrContainer interop.Hash160, keys []interop.PublicKey) { ctx := storage.GetContext() if !common.HasUpdateAccess(ctx) { panic("only owner can reinitialize contract") } + if len(addrBalance) != 20 || len(addrContainer) != 20 { + panic("init: incorrect length of contract script hash") + } + var irList []common.IRNode for i := 0; i < len(keys); i++ { @@ -79,6 +87,9 @@ func Init(owner interop.Hash160, keys []interop.PublicKey) { common.SetSerialized(ctx, snapshot0Key, []netmapNode{}) common.SetSerialized(ctx, snapshot1Key, []netmapNode{}) + storage.Put(ctx, balanceContractKey, addrBalance) + storage.Put(ctx, containerContractKey, addrContainer) + runtime.Log("netmap contract initialized") } @@ -218,6 +229,9 @@ func NewEpoch(epochNum int) bool { // put netmap into actual snapshot common.SetSerialized(ctx, snapshot0Key, dataOnlineState) + // make clean up routines in other contracts + cleanup(ctx, epochNum) + runtime.Notify("NewEpoch", epochNum) return true @@ -439,3 +453,11 @@ func multiaddress(n []common.IRNode, committee bool) []byte { return contract.CreateMultisigAccount(threshold, keys) } + +func cleanup(ctx storage.Context, epoch int) { + balanceContractAddr := storage.Get(ctx, balanceContractKey).(interop.Hash160) + contract.Call(balanceContractAddr, cleanupEpochMethod, contract.All, epoch) + + containerContractAddr := storage.Get(ctx, containerContractKey).(interop.Hash160) + contract.Call(containerContractAddr, cleanupEpochMethod, contract.All, epoch) +}