[#61] netmap: Invoke clean up methods on new epoch

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-17 16:58:56 +03:00 committed by Alex Vanin
parent a1f0919f98
commit 90f26e3ffd

View file

@ -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)
}