Skip to content

Commit

Permalink
locode: update with new locodedb package
Browse files Browse the repository at this point in the history
Removed command connected to locodedb generation. Import the new package
 into IR and CLI to do the same checks and queries. Removed IR DB
 configuration option.

 Refs: #2610.

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Oct 31, 2023
1 parent 219c49c commit 37a455b
Show file tree
Hide file tree
Showing 39 changed files with 88 additions and 2,274 deletions.
18 changes: 0 additions & 18 deletions cmd/neofs-cli/modules/util/locode.go

This file was deleted.

97 changes: 0 additions & 97 deletions cmd/neofs-cli/modules/util/locode_generate.go

This file was deleted.

57 changes: 0 additions & 57 deletions cmd/neofs-cli/modules/util/locode_info.go

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/neofs-cli/modules/util/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ func init() {
signCmd,
convertCmd,
keyerCmd,
locodeCmd,
)

initSignCmd()
initConvertCmd()
initKeyerCmd()
initLocodeCmd()
}
2 changes: 0 additions & 2 deletions cmd/neofs-ir/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func defaultConfiguration(cfg *viper.Viper) {

cfg.SetDefault("indexer.cache_timeout", 15*time.Second)

cfg.SetDefault("locode.db.path", "")

// extra fee values for working mode without notary contract
cfg.SetDefault("fee.main_chain", 5000_0000) // 0.5 Fixed8
cfg.SetDefault("fee.side_chain", 2_0000_0000) // 2.0 Fixed8
Expand Down
2 changes: 0 additions & 2 deletions config/example/ir.env
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ NEOFS_IR_GOVERNANCE_DISABLE=false

NEOFS_IR_NODE_PERSISTENT_STATE_PATH=.neofs-ir-state

NEOFS_IR_LOCODE_DB_PATH=/path/to/locode.db

NEOFS_IR_FEE_MAIN_CHAIN=50000000

NEOFS_IR_TIMERS_EMIT=240
Expand Down
4 changes: 0 additions & 4 deletions config/example/ir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ node:
persistent_state:
path: .neofs-ir-state # Path to application state file

locode:
db:
path: /path/to/locode.db # Path to UN/LOCODE database file

fee:
main_chain: 50000000 # Fixed8 value of extra GAS fee for mainchain contract invocation; ignore if notary is enabled in mainchain

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ retract (
v1.22.1 // Contains retraction only.
v1.22.0 // Published accidentally.
)

require github.com/nspcc-dev/locode-db v0.4.1-0.20231023164124-8d2bbc60340e
19 changes: 16 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -248,6 +258,8 @@ github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 h1:n4ZaF
github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U=
github.com/nspcc-dev/hrw v1.0.9 h1:17VcAuTtrstmFppBjfRiia4K2wA/ukXZhLFS8Y8rz5Y=
github.com/nspcc-dev/hrw v1.0.9/go.mod h1:l/W2vx83vMQo6aStyx2AuZrJ+07lGv2JQGlVkPG06MU=
github.com/nspcc-dev/locode-db v0.4.1-0.20231023164124-8d2bbc60340e h1:OesMl1cC84nkF70a3wG35qgGk8stD8ttNxHNIwNLMVg=
github.com/nspcc-dev/locode-db v0.4.1-0.20231023164124-8d2bbc60340e/go.mod h1:RZkcG3ftK2Q0ieZwxeLmohgt+gMmvr8rumx4L0w9e5o=
github.com/nspcc-dev/neo-go v0.102.0 h1:O2Gt4JPOWmp0c+PnPWwd2wPI74BKSwkaNCEyvyQTWJw=
github.com/nspcc-dev/neo-go v0.102.0/go.mod h1:QXxpZxJT2KedwM0Nlj8UO0/fZN2WIe4h/i03uBHKbnc=
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20230919154019-f66abd020d6a h1:ZF1T2PfRJh0LbQcMQAPMmp94B27o/6DKZV+zcMIUNHM=
Expand Down Expand Up @@ -277,6 +289,10 @@ github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/panjf2000/ants/v2 v2.8.2 h1:D1wfANttg8uXhC9149gRt1PDQ+dLVFjNXkCEycMcvQQ=
github.com/panjf2000/ants/v2 v2.8.2/go.mod h1:7ZxyxsqE4vvW0M7LSD8aI3cKwgFhBHbxnlN8mDqHa1I=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml/v2 v2.0.5 h1:ipoSadvV8oGUjnUbMub59IDPPwfxF694nG/jwbMiyQg=
github.com/pelletier/go-toml/v2 v2.0.5/go.mod h1:OMHamSCAODeSsVrwwvcJOaoN0LIUIaFVNZzmWyNfXas=
github.com/paulmach/orb v0.10.0 h1:guVYVqzxHE/CQ1KpfGO077TR0ATHSNjp4s6XGLn3W9s=
github.com/paulmach/orb v0.10.0/go.mod h1:5mULz1xQfs3bmQm63QEJA6lNGujuRafwA5S/EnuLaLU=
github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
Expand Down Expand Up @@ -329,7 +345,6 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
Expand Down Expand Up @@ -581,7 +596,6 @@ golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
Expand All @@ -590,7 +604,6 @@ golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
Expand Down
11 changes: 1 addition & 10 deletions pkg/innerring/innerring.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"io"
"net"
"sync/atomic"

Expand Down Expand Up @@ -310,18 +309,10 @@ func (s *Server) registerNoErrCloser(c func()) {
})
}

func (s *Server) registerIOCloser(c io.Closer) {
s.registerCloser(c.Close)
}

func (s *Server) registerCloser(f func() error) {
s.closers = append(s.closers, f)
}

func (s *Server) registerStarter(f func() error) {
s.starters = append(s.starters, f)
}

// New creates instance of inner ring sever structure.
func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<- error) (*Server, error) {
var err error
Expand Down Expand Up @@ -685,7 +676,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper, errChan chan<-
settlement.WithLogger(server.log),
)

locodeValidator, err := server.newLocodeValidator(cfg)
locodeValidator, err := server.newLocodeValidator()
if err != nil {
return nil, err
}
Expand Down
57 changes: 21 additions & 36 deletions pkg/innerring/locode.go
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
package innerring

import (
"github.com/nspcc-dev/locode-db/locodedb"

"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap"
irlocode "github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/nodevalidation/locode"
"github.com/nspcc-dev/neofs-node/pkg/util/locode"
locodedb "github.com/nspcc-dev/neofs-node/pkg/util/locode/db"
locodebolt "github.com/nspcc-dev/neofs-node/pkg/util/locode/db/boltdb"
"github.com/spf13/viper"
)

func (s *Server) newLocodeValidator(cfg *viper.Viper) (netmap.NodeValidator, error) {
locodeDB := locodebolt.New(locodebolt.Prm{
Path: cfg.GetString("locode.db.path"),
},
locodebolt.ReadOnly(),
)

s.registerStarter(locodeDB.Open)
s.registerIOCloser(locodeDB)

return irlocode.New(irlocode.Prm{
DB: (*locodeBoltDBWrapper)(locodeDB),
}), nil
}

type locodeBoltEntryWrapper struct {
*locodedb.Key
*locodedb.Record
func (s *Server) newLocodeValidator() (netmap.NodeValidator, error) {
return irlocode.New(), nil
}

func (l *locodeBoltEntryWrapper) LocationName() string {
return l.Record.LocationName()
}

type locodeBoltDBWrapper locodebolt.DB

func (l *locodeBoltDBWrapper) Get(lc *locode.LOCODE) (irlocode.Record, error) {
key, err := locodedb.NewKey(*lc)
func (s *Server) Get(lc string) (irlocode.Record, error) {
newLocode := [2]string{lc[:2], lc[2:]}
key, err := locodedb.NewKey(newLocode)
if err != nil {
return nil, err
return irlocode.Record{}, err
}

rec, err := (*locodebolt.DB)(l).Get(*key)
rec, err := locodedb.Get(lc)
if err != nil {
return nil, err
return irlocode.Record{}, err
}

return &locodeBoltEntryWrapper{
Key: key,
Record: rec,
if err != nil {
return irlocode.Record{}, err
}
return irlocode.Record{
CountryCode: key.CountryCode(),
CountryName: rec.Country,
LocationName: rec.Location,
LocationCode: key.LocationCode(),
SubDivCode: rec.SubDivCode,
SubDivName: rec.SubDivName,
Continent: rec.Cont,
}, nil
}
Loading

0 comments on commit 37a455b

Please sign in to comment.