Commit graph

755 commits

Author SHA1 Message Date
Tatiana Nesterenko
3abddc78c0 core: split ErrAlreadyExists into ErrAlreadyExists and ErrAlreadyInPool
ErrAlreadyExists is in blockchain and ErrAlreadyInPool is in mempool.

Signed-off-by: Tatiana Nesterenko <tatiana@nspcc.io>
2023-08-16 12:36:56 +01:00
Anna Shaleva
16d1d1e5eb rpcbinding: check duplicating struct fields before binding generation
RPC binding config may be malformed or the source .go contract may contain
structures like this:
```
type Str struct {
    Field int
    field int
}
```
We need to recognise these cases and return error. otherwise the resulting
binding can't be compiled.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-11 17:48:54 +03:00
Anna Shaleva
b4c0fcfaad cli: move RPC bindings related testdata to a separate folder
It helps us to keep the index clean and ordered. When some new RPC binding
test should be added, we don't need to search for a suitable place for it.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-11 17:03:04 +03:00
Anna Shaleva
1356721862 rpcbinding: export any unexported fields of structures/events
Perform private -> public transformation at the last step of RPC binding
generation so that it works not only with NeoGo contracts, but with any
other contracts.

Close #3083.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-11 15:31:08 +03:00
Anna Shaleva
c39153756a rpcsrv: carefully store Oracle service
And simplify atomic service value stored by RPC server. Oracle service can
either be an untyped nil or be the proper non-nil *oracle.Oracle.
Otherwise `submitoracleresponse` RPC handler doesn't work properly.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-10 10:12:01 +03:00
Anna Shaleva
6c1240d023 cli: fix failing TestRunWithHistoricState
Broken by #3084.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-08-09 15:26:38 +03:00
Anna Shaleva
bfe8867e63 cli: add test for incremental DB dump and restore
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-07-03 13:53:41 +03:00
Roman Khimov
a30f098f73 server: allow to create incremental dumps
Anything not starting from 0 is incremental by definition.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-06-29 11:41:33 +03:00
Anna Shaleva
802a2b3879 rpcbinding: call scriptFor* as method
Should be a part of #3035, otherwise generated bindings are failed to
be compiled.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-06-05 18:31:34 +03:00
Anna Shaleva
c7836ed6e7 rpcbinding: convert scriptFor* from function to method
Should be a part of #3012, otherwise generated bindings are failed to
be compiled.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-06-05 17:50:07 +03:00
Anna Shaleva
f97eaddfd1 cli: allow dynamic RPC binding contract hash
Close #3006 and make a light base for #3007.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-06-01 16:06:28 +03:00
Roman Khimov
772e723e8e
Merge pull request #3008 from nspcc-dev/event-gen
Close #2891.
2023-05-31 23:56:51 +03:00
Roman Khimov
8beb3f4515 *: drop legacy addresses from examples
They can't even be used now because they'll fail the conversion.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2023-05-31 18:32:02 +03:00
Anna Shaleva
9f9cec53bd rpcbinding: provide links to types in comments
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
8ae4a1e957 rpcbinding: adjust comment of FromStackItem template methods
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
2ce1454ef5 cli: improve error message for binding template
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
44dfe8342d compiler: disallow named types redeclaration via contract config
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
865bd6c9cc compiler: compare emitted event params if --guess-eventtypes enabled
In this case emitted event parameters should match from invocation to
invocation. It's an error otherwise (and if the type is not Any).

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
6379bcc15a compiler: properly set extended type name for unnamed structs
After the struct was registered as "unnamed", it has the own unique name.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
0195aae824 cli: add test for --guessed-eventtypes RPC binding generator flag
Currently we have problems with unnamed structs used as a parameter for
notifications, because there's no one-to-one correspondence between
notification parameter and the list of extended types used by the whole
contract. Otherwise eventtypes guessing works OK.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
3e2755e66d smartcontract: add test for user-defined extended event types configuration
config_extended.yml contains an example of user-defined configuration
file with extended event types. User-defined event types are allowed
to be named and complicated, i.e. properly support extended types
notation.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
a0d991a500 rpcbinding: support map[any]any conversion for extended types
Unfortunately, without pre-set user extended types configuration for events
and without --guess-eventtypes flag set we are allowed to rely only on manifest
information about types. Manifest can't give us a lot of information, but we
still need to be able to generate RPC binding. Arrays and structs are correctly
handled by the current code, but maps always rely on the fact that map's value
type is set. It's not true in the described case, so make the maps type convertor
handle this situation in a similar way how arrays are handled.

Without this commit the following panic occurs on attempt to generate RPC binding:
```
    --- FAIL: TestAssistedRPCBindings/testdata/notifications (0.01s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f7c0e]

goroutine 190 [running]:
testing.tRunner.func1.2({0x109cb40, 0x1d58760})
	/usr/local/go/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1399 +0x39f
panic({0x109cb40, 0x1d58760})
	/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.extendedTypeToGo({0x22, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, {0x0, 0x0, 0x0}}, ...)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:515 +0x36e
github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.scTypeToGo({0xc000206d92?, 0xc000206d80?}, 0x22, 0xc0005d70e0)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:643 +0x138
github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.scTemplateToRPC({{0xc00049bb07, 0x7}, 0xc0004c89c0, {0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, ...}, ...}, ...)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:686 +0xbc4
github.com/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding.Generate({{0xc00049bb07, 0x7}, 0xc0004c89c0, {0x33, 0x22, 0x11, 0x0, 0xff, 0xee, 0xdd, ...}, ...})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/smartcontract/rpcbinding/binding.go:421 +0x387
github.com/nspcc-dev/neo-go/cli/smartcontract.contractGenerateSomething(0xc00043e2c0, 0x137cd00)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate.go:99 +0x855
github.com/nspcc-dev/neo-go/cli/smartcontract.contractGenerateRPCWrapper(0xc00043e2c0?)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate.go:60 +0x25
github.com/urfave/cli.HandleAction({0x1048380?, 0x137c660?}, 0x13?)
	/home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:524 +0x50
github.com/urfave/cli.Command.Run({{0x123539d, 0x13}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x12577ad, 0x2a}, {0x127ad35, ...}, ...}, ...)
	/home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:173 +0x65b
github.com/urfave/cli.(*App).RunAsSubcommand(0xc0001f4000, 0xc00043e000)
	/home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:405 +0x91b
github.com/urfave/cli.Command.startApp({{0x12281e1, 0x8}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1254d8a, 0x28}, {0x0, ...}, ...}, ...)
	/home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:372 +0x6e7
github.com/urfave/cli.Command.Run({{0x12281e1, 0x8}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0x1254d8a, 0x28}, {0x0, ...}, ...}, ...)
	/home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/command.go:102 +0x825
github.com/urfave/cli.(*App).Run(0xc00024e000, {0xc0004f6420, 0xb, 0xb})
	/home/anna/go/pkg/mod/github.com/urfave/cli@v1.22.5/app.go:277 +0x8a7
github.com/nspcc-dev/neo-go/cli/smartcontract.TestAssistedRPCBindings.func1.1(0x9f8829?)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/cli/smartcontract/generate_test.go:395 +0x5fc
testing.tRunner(0xc0006824e0, 0xc0004a3680)
	/usr/local/go/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1493 +0x35f
```

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
37af2031bb rpcbinding: properly add imports for simple types of event parameters
There are two ways of doing this: first one is to emit all notifications
parameter data into rpcbindings configuration on compile time (event if
the parameter has a simple type), and the second one is to fetch parameter
type from the manifest on rpcbinding file generation if needed (we always
have manifest at this stage, thus it's not a problem to retrieve necessary
information). The latter case is chosen to reduce the bindings configuration
file size.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
19cc6c6369 compiler: store ready-to-use notification names in bindings config
Notification and its parameters may have any UTF8-compatible name
which is inappropriate for bindings configuration and for the resulting
RPC bindings file. This commit stores the prettified version of
notification's name and parameters that are ready to be used in the
resulting RPC binding without any changes.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
41938ffa78 smartcontract: drop standard events before RPC binging generation
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:43 +03:00
Anna Shaleva
e2580187a1 cli: fetch extended evet types from contract config
The user should specify it via parameter's `extendedtype` field and
via upper-level `namedtypes` field of the contract configuration YAML.

Also, as we have proper event structure source, make the `--guess-eventtype`
compilation option and make event types guess optional.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:53:41 +03:00
Anna Shaleva
044ae477ca smartconract: generate RPC binding wrappers for events
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-31 15:52:39 +03:00
Anna Shaleva
ae52b2c2fa rpcbinding: fix binding indentation
New rule for writing blocks of code to our template: new line before
the block starts and new line after the block ends. This rule is the
same as the one we use during manual typing.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-30 17:37:06 +03:00
Anna Shaleva
0f0f7b364f rpcbinding: use typed return err value in etTypeConverter
Otherwise the resulting code can't be compiled.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-25 16:41:23 +03:00
Anna Shaleva
36af361c2b smartcontract: add FromStackItem wrapper for RPC bindings
Make it exported and reusable from the user's code.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-24 11:27:49 +03:00
Anna Shaleva
7a06cea885 cli: allow to rewrite expected test output
Don't perform it manually every time.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-24 11:27:48 +03:00
Anna Shaleva
ddfbf7a434 cli: remove code duplication in test
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-19 13:26:56 +03:00
Anna Shaleva
2f4fb3a079 cli: fix error description for run VM CLI command
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-19 13:26:56 +03:00
Anna Shaleva
b6b80f3abf cli: properly handle run VM CLI command
Properly load the provided method using NEF and hash specified. It allows
to have NEF properly set in the VM context and handle CALLT instruction
correctly.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-19 13:26:56 +03:00
Anna Shaleva
aace790651 cli: guess manifest filename from nef for loadnef VM CLI command
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-17 13:09:31 +03:00
Anna Shaleva
ed2b59e077 cli: use cosigners separator for VM CLI commands where appropriate
Needed for further VM CLI commands improvement, we'll add another
positional args.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-17 13:09:31 +03:00
Anna Shaleva
a2449ae8ae cli: autocomplete output filenames for contract compile cmd
It's enough to specify the input file only to get the standard output:
```
$ neo-go contract compile -i ./1-print/1-print.go
$ neo-go contract compile -i ./1-print/
```

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-17 13:09:30 +03:00
Anna Shaleva
3dbb733324 cli: require contract config file for bindings generation
It's an error if config file isn't provided and bindings config needs
to be generated.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-17 13:00:39 +03:00
Anna Shaleva
4be9e4347a cli: allow to provide network-specific node config file
Close #2978.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-05-16 13:23:55 +03:00
Roman Khimov
a4cc6da766
Merge pull request #2966 from nspcc-dev/bugfix/2896-rpc-shutdown-deadlock
rpc: Fix deadlock produced during server shutdown
2023-04-17 10:36:30 +03:00
Leonard Lyubich
e29c33e449 cli/node: Fix deadlock produced by instant RPC service start
If `StartWhenSynchronized` is unset in config, `node` command runs RPC
service instantly. Previously there was a ground for deadlock. Command
started RPC server synchronously. According to server implementation, it
sends all internal failures to the parameterized error channel. Deadlock
occured because main routine didn't scan the channel.

Run `rpcsrv.Server.Start` in a separate go-routine in `startServer`.
This prevents potential deadlock caused by writing into unread channel.

Fixes #2896.

Signed-off-by: Leonard Lyubich <leonard@morphbits.io>
2023-04-17 10:42:50 +04:00
Anna Shaleva
55ab38ed81 network: do not use error channel to start network srv
It's obsolete thing, we have looger and it perfectly suits our needs.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-04-13 13:21:34 +03:00
Anna Shaleva
541da7e83b cli: add util ops command
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
2023-04-12 17:12:18 +03:00
Roman Khimov
a80d7bef80
Merge pull request #2889 from nspcc-dev/ask-nep2-label
cli: ask for NEP2 account label if not provided
2023-04-06 10:42:52 +03:00
Roman Khimov
e2cf5b868a
Merge pull request #2941 from nspcc-dev/drop-deprecated-0.102.0
Drop some deprecated things in 0.102.0
2023-04-06 10:42:26 +03:00
Anna Shaleva
6b21ad9922 *: replace interface{} with any keyword
Everywhere including examples, external interop APIs, bindings generators
code and in other valuable places. A couple of `interface{}` usages are
intentionally left in the CHANGELOG.md, documentation and tests.
2023-04-04 13:22:42 +03:00
Anna Shaleva
110356857d *: drop go 1.17 support for github actions and tests
And support go 1.20 for github workflows.
2023-03-31 10:20:56 +03:00
Roman Khimov
4671fbb3be interop: drop deprecated util.FromAddress
It still was used in a number of places, surprisingly.
2023-03-18 10:44:12 +03:00
Anna Shaleva
0cbef58b3c consensus: enqueue newly created blocks
Do not add them directly to chain, it will be done by the block queue
manager. Close https://github.com/nspcc-dev/neo-go/issues/2923. However,
this commit is not valid without
https://github.com/roman-khimov/dbft/pull/4.
It's the neo-go's duty to initialize consensus after subsequent block
addition; the dBFT itself must wait for the neo-go to complete the block
addition and notify the dBFT, so that it can initialize at 0-th view to
collect the next block.
2023-03-15 17:37:47 +03:00
Anna Shaleva
5f6c01336c *: add nolint comments to multiple errors wrapping
To be enabled after go 1.20 support is added.
2023-03-15 16:38:01 +03:00