From 787bd3b63cd2b662efdb7ff90ee9b95c612e1907 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 21 Jul 2021 14:45:32 +0300 Subject: [PATCH] [#110] netmap: Store block number of last epoch Signed-off-by: Alex Vanin --- netmap/netmap_contract.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/netmap/netmap_contract.go b/netmap/netmap_contract.go index afb4a85..13ec204 100644 --- a/netmap/netmap_contract.go +++ b/netmap/netmap_contract.go @@ -5,6 +5,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/interop/contract" "github.com/nspcc-dev/neo-go/pkg/interop/iterator" "github.com/nspcc-dev/neo-go/pkg/interop/native/crypto" + "github.com/nspcc-dev/neo-go/pkg/interop/native/ledger" "github.com/nspcc-dev/neo-go/pkg/interop/native/management" "github.com/nspcc-dev/neo-go/pkg/interop/native/std" "github.com/nspcc-dev/neo-go/pkg/interop/runtime" @@ -37,9 +38,10 @@ const ( notaryDisabledKey = "notary" innerRingKey = "innerring" - snapshot0Key = "snapshotCurrent" - snapshot1Key = "snapshotPrevious" - snapshotEpoch = "snapshotEpoch" + snapshot0Key = "snapshotCurrent" + snapshot1Key = "snapshotPrevious" + snapshotEpoch = "snapshotEpoch" + snapshotBlockKey = "snapshotBlock" containerContractKey = "containerScriptHash" balanceContractKey = "balanceScriptHash" @@ -86,6 +88,7 @@ func _deploy(data interface{}, isUpdate bool) { // epoch number is a little endian int, it doesn't need to be serialized storage.Put(ctx, snapshotEpoch, 0) + storage.Put(ctx, snapshotBlockKey, 0) common.SetSerialized(ctx, snapshot0Key, []netmapNode{}) common.SetSerialized(ctx, snapshot1Key, []netmapNode{}) @@ -341,6 +344,7 @@ func NewEpoch(epochNum int) { // todo: check if provided epoch number is bigger than current storage.Put(ctx, snapshotEpoch, epochNum) + storage.Put(ctx, snapshotBlockKey, ledger.CurrentIndex()) // put actual snapshot into previous snapshot common.SetSerialized(ctx, snapshot1Key, data0snapshot) @@ -359,6 +363,11 @@ func Epoch() int { return storage.Get(ctx, snapshotEpoch).(int) } +func LastEpochBlock() int { + ctx := storage.GetReadOnlyContext() + return storage.Get(ctx, snapshotBlockKey).(int) +} + func Netmap() []storageNode { ctx := storage.GetReadOnlyContext() return getSnapshot(ctx, snapshot0Key)