Skip to content

Commit

Permalink
[#110] netmap: Store block number of last epoch
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Vanin <[email protected]>
  • Loading branch information
alexvanin committed Jul 22, 2021
1 parent 5a95c8e commit 787bd3b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions netmap/netmap_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 787bd3b

Please sign in to comment.