forked from TrueCloudLab/frostfs-contract
[#61] netmap: Invoke clean up methods on new epoch
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
a1f0919f98
commit
90f26e3ffd
1 changed files with 23 additions and 1 deletions
|
@ -39,6 +39,10 @@ const (
|
||||||
snapshot0Key = "snapshotCurrent"
|
snapshot0Key = "snapshotCurrent"
|
||||||
snapshot1Key = "snapshotPrevious"
|
snapshot1Key = "snapshotPrevious"
|
||||||
snapshotEpoch = "snapshotEpoch"
|
snapshotEpoch = "snapshotEpoch"
|
||||||
|
|
||||||
|
containerContractKey = "containerScriptHash"
|
||||||
|
balanceContractKey = "balanceScriptHash"
|
||||||
|
cleanupEpochMethod = "newEpoch"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -53,13 +57,17 @@ var (
|
||||||
|
|
||||||
// Init function sets up initial list of inner ring public keys and should
|
// Init function sets up initial list of inner ring public keys and should
|
||||||
// be invoked once at neofs infrastructure setup.
|
// 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()
|
ctx := storage.GetContext()
|
||||||
|
|
||||||
if !common.HasUpdateAccess(ctx) {
|
if !common.HasUpdateAccess(ctx) {
|
||||||
panic("only owner can reinitialize contract")
|
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
|
var irList []common.IRNode
|
||||||
|
|
||||||
for i := 0; i < len(keys); i++ {
|
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, snapshot0Key, []netmapNode{})
|
||||||
common.SetSerialized(ctx, snapshot1Key, []netmapNode{})
|
common.SetSerialized(ctx, snapshot1Key, []netmapNode{})
|
||||||
|
|
||||||
|
storage.Put(ctx, balanceContractKey, addrBalance)
|
||||||
|
storage.Put(ctx, containerContractKey, addrContainer)
|
||||||
|
|
||||||
runtime.Log("netmap contract initialized")
|
runtime.Log("netmap contract initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +229,9 @@ func NewEpoch(epochNum int) bool {
|
||||||
// put netmap into actual snapshot
|
// put netmap into actual snapshot
|
||||||
common.SetSerialized(ctx, snapshot0Key, dataOnlineState)
|
common.SetSerialized(ctx, snapshot0Key, dataOnlineState)
|
||||||
|
|
||||||
|
// make clean up routines in other contracts
|
||||||
|
cleanup(ctx, epochNum)
|
||||||
|
|
||||||
runtime.Notify("NewEpoch", epochNum)
|
runtime.Notify("NewEpoch", epochNum)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -439,3 +453,11 @@ func multiaddress(n []common.IRNode, committee bool) []byte {
|
||||||
|
|
||||||
return contract.CreateMultisigAccount(threshold, keys)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue