Skip to content

Commit

Permalink
Merge branch 'support/v0.16' into master
Browse files Browse the repository at this point in the history
* origin/support/v0.16:
  common: bump version, do netmap migrations pre-0.16.0
  netmap: migrate candidate states for pre-0.16.0
  netmap: fix infinite loop in pre-0.16.0 migration code
  [#300] container: Allow to iterate over container list
  [#293] container: Add IterateContainerSizes method
  [#296] container: Increase default expiration time
  [#291] Debian packaging
  • Loading branch information
roman-khimov committed Jan 16, 2023
2 parents 9052ec6 + 1d65762 commit 7a29056
Show file tree
Hide file tree
Showing 18 changed files with 491 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ config.json
/vendor/
.idea
/bin/

# debhelpers
**/.debhelper
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export GOBIN ?= $(shell pwd)/bin
NEOGO ?= $(GOBIN)/cli
VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")


# .deb package versioning
OS_RELEASE = $(shell lsb_release -cs)
PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \
sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \
sed "s/-/~/")-${OS_RELEASE}

.PHONY: all build clean test neo-go
.PHONY: alphabet mainnet morph nns sidechain
.PHONY: debpackage debclean
build: neo-go all
all: sidechain mainnet
sidechain: alphabet morph nns
Expand Down Expand Up @@ -58,3 +66,15 @@ archive: build
@tar --transform "s|^./|neofs-contract-$(VERSION)/|" \
-czf neofs-contract-$(VERSION).tar.gz \
$(shell find . -name '*.nef' -o -name 'config.json')

# Package for Debian
debpackage:
dch --package neofs-contract \
--controlmaint \
--newversion $(PKG_VERSION) \
--distribution $(OS_RELEASE) \
"Please see CHANGELOG.md for code changes for $(VERSION)"
dpkg-buildpackage --no-sign -b

debclean:
dh clean
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ $ NEOGO=/home/user/neo-go/bin/neo-go make all

Remove compiled files with `make clean` or `make mr_proper` command.

## Building Debian package

To build Debian package containing compiled contracts, run `make debpackage`
command. Package will install compiled contracts `*_contract.nef` and manifest
`config.json` with corresponding directories to `/var/lib/neofs/contract` for
further usage.
It will download and build neo-go, if needed.

To clean package-related files, use `make debclean`.

# Testing
Smartcontract tests reside in `tests/` directory. To execute test suite
after applying changes, simply run `make test`.
Expand Down
2 changes: 1 addition & 1 deletion container/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "NeoFS Container"
safemethods: ["count", "get", "owner", "list", "eACL", "getContainerSize", "listContainerSizes", "version"]
safemethods: ["count", "containersOf", "get", "owner", "list", "eACL", "getContainerSize", "listContainerSizes", "iterateContainerSizes", "version"]
permissions:
- methods: ["update", "addKey", "transferX",
"register", "addRecord", "deleteRecords"]
Expand Down
85 changes: 64 additions & 21 deletions container/container_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (

singleEstimatePrefix = "est"
estimateKeyPrefix = "cnr"
containerKeyPrefix = 'x'
ownerKeyPrefix = 'o'
estimatePostfixSize = 10
// CleanupDelta contains the number of the last epochs for which container estimations are present.
CleanupDelta = 3
Expand All @@ -74,10 +76,10 @@ const (
NotFoundError = "container does not exist"

// default SOA record field values
defaultRefresh = 3600 // 1 hour
defaultRetry = 600 // 10 min
defaultExpire = 604800 // 1 week
defaultTTL = 3600 // 1 hour
defaultRefresh = 3600 // 1 hour
defaultRetry = 600 // 10 min
defaultExpire = 3600 * 24 * 365 * 10 // 10 years
defaultTTL = 3600 // 1 hour
)

var (
Expand All @@ -93,6 +95,26 @@ func _deploy(data interface{}, isUpdate bool) {
if isUpdate {
args := data.([]interface{})
common.CheckVersion(args[len(args)-1].(int))

it := storage.Find(ctx, []byte{}, storage.None)
for iterator.Next(it) {
item := iterator.Value(it).(struct {
key []byte
value []byte
})

// Migrate container.
if len(item.key) == containerIDSize {
storage.Delete(ctx, item.key)
storage.Put(ctx, append([]byte{containerKeyPrefix}, item.key...), item.value)
}

// Migrate owner-cid map.
if len(item.key) == 25 /* owner id size */ +containerIDSize {
storage.Delete(ctx, item.key)
storage.Put(ctx, append([]byte{ownerKeyPrefix}, item.key...), item.value)
}
}
return
}

Expand Down Expand Up @@ -391,17 +413,24 @@ func Owner(containerID []byte) []byte {
func Count() int {
count := 0
ctx := storage.GetReadOnlyContext()
it := storage.Find(ctx, []byte{}, storage.KeysOnly)
it := storage.Find(ctx, []byte{containerKeyPrefix}, storage.KeysOnly)
for iterator.Next(it) {
key := iterator.Value(it).([]byte)
// V2 format
if len(key) == containerIDSize {
count++
}
count++
}
return count
}

// ContainersOf iterates over all container IDs owned by the specified owner.
// If owner is nil, it iterates over all containers.
func ContainersOf(owner []byte) iterator.Iterator {
ctx := storage.GetReadOnlyContext()
key := []byte{ownerKeyPrefix}
if len(owner) != 0 {
key = append(key, owner...)
}
return storage.Find(ctx, key, storage.ValuesOnly)
}

// List method returns a list of all container IDs owned by the specified owner.
func List(owner []byte) [][]byte {
ctx := storage.GetReadOnlyContext()
Expand All @@ -412,7 +441,7 @@ func List(owner []byte) [][]byte {

var list [][]byte

it := storage.Find(ctx, owner, storage.ValuesOnly)
it := storage.Find(ctx, append([]byte{ownerKeyPrefix}, owner...), storage.ValuesOnly)
for iterator.Next(it) {
id := iterator.Value(it).([]byte)
list = append(list, id)
Expand Down Expand Up @@ -551,7 +580,7 @@ func GetContainerSize(id []byte) containerSizes {
}

// ListContainerSizes method returns the IDs of container size estimations
// that has been registered for the specified epoch.
// that have been registered for the specified epoch.
func ListContainerSizes(epoch int) [][]byte {
ctx := storage.GetReadOnlyContext()

Expand Down Expand Up @@ -582,6 +611,19 @@ func ListContainerSizes(epoch int) [][]byte {
return result
}

// IterateContainerSizes method returns iterator over container size estimations
// that have been registered for the specified epoch.
func IterateContainerSizes(epoch int) iterator.Iterator {
ctx := storage.GetReadOnlyContext()

var buf interface{} = epoch

key := []byte(estimateKeyPrefix)
key = append(key, buf.([]byte)...)

return storage.Find(ctx, key, storage.DeserializeValues)
}

// NewEpoch method removes all container size estimations from epoch older than
// epochNum + 3. It can be invoked only by NewEpoch method of the Netmap contract.
func NewEpoch(epochNum int) {
Expand Down Expand Up @@ -687,29 +729,30 @@ func Version() int {
}

func addContainer(ctx storage.Context, id, owner []byte, container Container) {
containerListKey := append(owner, id...)
containerListKey := append([]byte{ownerKeyPrefix}, owner...)
containerListKey = append(containerListKey, id...)
storage.Put(ctx, containerListKey, id)

common.SetSerialized(ctx, id, container)
idKey := append([]byte{containerKeyPrefix}, id...)
common.SetSerialized(ctx, idKey, container)
}

func removeContainer(ctx storage.Context, id []byte, owner []byte) {
containerListKey := append(owner, id...)
containerListKey := append([]byte{ownerKeyPrefix}, owner...)
containerListKey = append(containerListKey, id...)
storage.Delete(ctx, containerListKey)

storage.Delete(ctx, id)
storage.Delete(ctx, append([]byte{containerKeyPrefix}, id...))
}

func getAllContainers(ctx storage.Context) [][]byte {
var list [][]byte

it := storage.Find(ctx, []byte{}, storage.KeysOnly)
it := storage.Find(ctx, []byte{containerKeyPrefix}, storage.KeysOnly|storage.RemovePrefix)
for iterator.Next(it) {
key := iterator.Value(it).([]byte) // it MUST BE `storage.KeysOnly`
// V2 format
if len(key) == containerIDSize {
list = append(list, key)
}
list = append(list, key)
}

return list
Expand All @@ -726,7 +769,7 @@ func getEACL(ctx storage.Context, cid []byte) ExtendedACL {
}

func getContainer(ctx storage.Context, cid []byte) Container {
data := storage.Get(ctx, cid)
data := storage.Get(ctx, append([]byte{containerKeyPrefix}, cid...))
if data != nil {
return std.Deserialize(data.([]byte)).(Container)
}
Expand Down
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
neofs-contract (0.0.0) stable; urgency=medium

* Initial release

-- NeoSPCC <[email protected]> Wed, 24 Aug 2022 18:29:49 +0300
34 changes: 34 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Source: neofs-contract
Section: misc
Priority: optional
Maintainer: NeoSPCC <[email protected]>
Build-Depends: debhelper-compat (= 13), git, devscripts, neo-go
Standards-Version: 4.5.1
Homepage: https://fs.neo.org/
Vcs-Git: https://github.com/nspcc-dev/neofs-contract.git
Vcs-Browser: https://github.com/nspcc-dev/neofs-contract

Package: neofs-contract
Architecture: all
Depends: ${misc:Depends}
Description: NeoFS-Contract contains all NeoFS related contracts.
Contracts are written for neo-go compiler.
These contracts are deployed both in the mainchain and the sidechain.
.
Mainchain contracts:
.
- neofs
- processing
.
Sidechain contracts:
.
- alphabet
- audit
- balance
- container
- neofsid
- netmap
- nns
- proxy
- reputation
- subnet
22 changes: 22 additions & 0 deletions debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: neofs-contract
Upstream-Contact: [email protected]
Source: https://github.com/nspcc-dev/neofs-contract

Files: *
Copyright: 2018-2022 NeoSPCC (@nspcc-dev)

License: GPL-3
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program or at /usr/share/common-licenses/GPL-3.
If not, see <http://www.gnu.org/licenses/>.
1 change: 1 addition & 0 deletions debian/neofs-contract.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
README*
39 changes: 39 additions & 0 deletions debian/postinst.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/sh
# postinst script for neofs-contract
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
configure)
;;

abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
37 changes: 37 additions & 0 deletions debian/postrm.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh
# postrm script for neofs-contract
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
;;

*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
Loading

0 comments on commit 7a29056

Please sign in to comment.