Commit graph

6190 commits

Author SHA1 Message Date
Roman Khimov
a2c4a7f611 rpcsrv: adjust for paid attritbutes in calculatenetworkfee
calculatenetworkfee MUST calculate complete proper network fee, if we have
some extensions enabled and some attributes should be paid for that they're a
part of the equation too.
2022-08-23 15:34:18 +03:00
Roman Khimov
f3d83c90b1 rpcsrv: allow invalid contract signatures in calculatenetworkfee
See #2805, it allows to cover more cases like Notary contract that can use
CalculateNetworkFee now instead of AddNetworkFee RPC client API.
2022-08-22 14:55:45 +03:00
Roman Khimov
98dfe66466 rpcsrv: simplify calculatenetworkfee
We're dealing with a transaction here and it can't be decoded successfully
unless it has an appropriate number of witness scripts (matching the number of
signers) with appropriate hashes (matching signers). So this iterations make
no sense at all, we know exactly where to look for the
verification/invocation scripts.
2022-08-22 14:47:30 +03:00
Roman Khimov
9916832e2e core: set Tx for interop.Context when verifying witnesses
Notary contract uses it in the verification context and it's not harmful to
have it always be there when it's there.
2022-08-22 13:38:43 +03:00
Roman Khimov
606597b9a1
Merge pull request #2652 from nspcc-dev/shutdown-fixes
Shutdown sequence fixes
2022-08-22 10:22:54 +03:00
Roman Khimov
d2cf5b5532
Merge pull request #2653 from nspcc-dev/nep17-multi
NEP-17 multitransfers
2022-08-22 10:22:38 +03:00
Roman Khimov
8005bfcd32 cli/wallet: compensate for CLI waiting time
Similar to ba2e7063dd.
2022-08-22 09:55:31 +03:00
Roman Khimov
f60fa02a96 cli/wallet: deduplicate some transfer code 2022-08-22 09:55:31 +03:00
Roman Khimov
779a5c070f network: wait for exit in discoverer
And synchronize other threads with channels instead of mutexes. Overall this
scheme is more reliable.
2022-08-19 22:23:47 +03:00
Roman Khimov
eeeb0f6f0e core: accept two-side channels for sub/unsub, read on unsub
Blockchain's notificationDispatcher sends events to channels and these
channels must be read from. Unfortunately, regular service shutdown procedure
does unsubscription first (outside of the read loop) and only then drains the
channel. While it waits for unsubscription request to be accepted
notificationDispatcher can try pushing more data into the same channel which
will lead to a deadlock. Reading in the same method solves this, any number of
events can be pushed until unsub channel accepts the data.
2022-08-19 22:08:40 +03:00
Roman Khimov
dea75a4211 network: wait for the relayer thread to finish on shutdown
Unsubscribe and drain first, then return from the Shutdown method. It's
important wrt to subsequent chain shutdown process (normally it's closed right
after the network server).
2022-08-19 22:08:40 +03:00
Roman Khimov
3402b870c8 fixedn: add a test for empty string
Ensure it fails.
2022-08-19 21:52:43 +03:00
Roman Khimov
7e212de41a cli: drop the use of deprecated APIs from sc/nep11/nep17 2022-08-19 21:52:43 +03:00
Roman Khimov
b2524a3ba9 actor: add Sender helper method 2022-08-19 21:52:43 +03:00
Roman Khimov
c034f94a94 nep17: provide out of the box multitransfer capability
It can't replicate the old multitransfer methods in ability to transfer
multiple tokens, but it at the same time can do multiple senders.
2022-08-19 21:52:43 +03:00
Roman Khimov
155089f4e5 network: drop cleanup from TestVerifyNotaryRequest
It never runs the server, so 746644a4eb was a
bit wrong with this.
2022-08-19 20:54:06 +03:00
Roman Khimov
823c4b38fc
Merge pull request #2651 from nspcc-dev/nep-11-wrapper
NEP-11 RPC wrapper
2022-08-19 11:43:26 +03:00
Roman Khimov
194933a5cc rpcclient: provide nep11 package for NEP-11 tokens
Unfortunately Go doesn't allow to easily reuse readers in full packages, still
we can have this wrapper with a little overhead (the alternative is to move
specific methods into types of their own, but I'm not sure how it's going to
be accepted user-side).
2022-08-19 10:37:22 +03:00
Roman Khimov
d0702c2cf9 unwrap: provide ArrayOfUint160
It's a popular type as well.
2022-08-19 10:36:44 +03:00
Roman Khimov
8cd4948e06
Merge pull request #2650 from nspcc-dev/neo-wrapper
NEO RPC wrapper
2022-08-19 10:34:41 +03:00
Roman Khimov
06f50630ac
Merge pull request #2644 from nspcc-dev/fix-gen-decl
compiler: allow multi-return variables declaration
2022-08-18 17:44:50 +03:00
Roman Khimov
c056c641d2
Merge pull request #2641 from anikeev-yadro/filter-version-tag
Makefile: Filter version tags for version calculation
2022-08-18 14:58:56 +03:00
Roman Khimov
6082383e3c
Merge pull request #2649 from nspcc-dev/fix-unnamed-rcvr
compiler: fix nil method receiver handling
2022-08-18 12:23:17 +03:00
7340a0609c Use only v-prefixed tags for version calculation
This allows us to use any custom tags along with tags that denote releases.

Signed-off-by: anikeev-yadro <a.anikeev@yadro.com>
2022-08-18 11:55:03 +03:00
Roman Khimov
e23fc11da5
Merge pull request #2648 from nspcc-dev/restrict-multi-ret
compiler: adjust restrictions imposed on manifest functions
2022-08-17 22:03:21 +03:00
Roman Khimov
f011b3c3dd rpcclient: introduce NEO wrapper
Notice that int64 types are used for gas per block or registration price
because the price has to fit into the system fee limitation and gas per block
value can't be more than 10 GAS. We use int64 for votes as well in other types
since NEO is limited to 100M.
2022-08-17 22:03:09 +03:00
Anna Shaleva
16dbb35bd8 compiler: fix nil method receiver handling
An attempt to compile the following code leads to runtime panic:
```
package foo
type CustomInt int
func Main() int {
	var i CustomInt
	i = 5
	return i.Do(2)
}
func (CustomInt) Do(arg int) int {
	return arg
}
```
The panic:
```
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 22 [running]:
testing.tRunner.func1.2({0xa341c0, 0xc0001606d8})
	/usr/local/go/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1212 +0x218
panic({0xa341c0, 0xc0001606d8})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertFuncDecl(0xc00015e3c0, {0xc753b8, 0xc000152c80}, 0xc000266300, 0x30)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:497 +0x10b3
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).compile.func2(0xc000152c80, 0xc00023c410)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:2153 +0x3f8
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).ForEachFile.func1(0xc000229b80)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/compiler.go:102 +0x82
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).ForEachPackage(0xc00015e3c0, 0xc000189bb0)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/compiler.go:93 +0xc6
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).ForEachFile(0x999a20, 0xc000130d80)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/compiler.go:99 +0x45
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).compile(0xc00015e3c0, 0xc0002669f0, 0x1)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:2140 +0x445
github.com/nspcc-dev/neo-go/pkg/compiler.codeGen(0xc0002669f0)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:2191 +0x353
github.com/nspcc-dev/neo-go/pkg/compiler.CompileWithOptions({0xa6f39a, 0x50b6b3}, {0xc6d1a0, 0xc0002421e0}, 0x0)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/compiler.go:218 +0x65
github.com/nspcc-dev/neo-go/pkg/compiler_test.vmAndCompileInterop(0x5648df, {0xa9bf23, 0x94})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/vm_test.go:75 +0x113
github.com/nspcc-dev/neo-go/pkg/compiler_test.eval(0xc0002421c0, {0xa9bf23, 0x61be8c7}, {0xa68880, 0xc0002421c0})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/vm_test.go:36 +0x2d
github.com/nspcc-dev/neo-go/pkg/compiler_test.TestUnnamedMethodReceiver(0x4079f9)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/function_call_test.go:400 +0x4f
testing.tRunner(0xc000204b60, 0xbcebb0)
	/usr/local/go/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1306 +0x35a

```

The solution is to use the same approach as for unnamed function
parameters handling introduced in #2204. (c *funcScope).newVariable is
able to properly handle "_" receiver.
2022-08-17 17:44:57 +03:00
Roman Khimov
79051f21c1 invoker: expand the interface with iterator wrappers
We need them for iterator-based interfaces. Invoker hides the difference
between different (session/expanded) iterators here.
2022-08-17 16:38:03 +03:00
Anna Shaleva
9b9d72937b compiler: restrict return values count for manifest methods
Exported functions from main package shouldn't have more than one return
value.
2022-08-17 15:42:56 +03:00
Anna Shaleva
171364f07f compiler: allow unnamed params for exported methods
Adjust the result of #2601.
2022-08-17 15:41:19 +03:00
Roman Khimov
689331b960 unwrap: perform consistency check in SessionIterator
C# servers with SessionEnabled=false will return iterator IDs and no session
IDs which can be reported as an error immediately because the iterator can't
be traversed.
2022-08-17 15:08:24 +03:00
Roman Khimov
37619743ad unwrap: add ArrayOfPublicKeys()
This type of result is also popular in the NEO contract.
2022-08-17 12:45:46 +03:00
Roman Khimov
cdc2a762a1
Merge pull request #2646 from nspcc-dev/more-native-contract-rpc-wrappers
More native contract RPC wrappers
2022-08-17 12:40:17 +03:00
Roman Khimov
0dbe8b6ce2 rpcclient: add oracle package for OracleContract 2022-08-17 11:42:20 +03:00
Roman Khimov
5c8f3a99dc rpcclient: add management wrapper for ContractManagement 2022-08-17 11:42:20 +03:00
Roman Khimov
ab577da2b5
Merge pull request #2645 from nspcc-dev/fix-vm-cli-panic
compiler: avoid panic on empty package list
2022-08-17 11:37:38 +03:00
Anna Shaleva
0bca027f99 compiler: avoid panic on empty package list
An attempt to compile unexisting file via neo-go-vm CLI leads to the following
panic:
```
NEO-GO-VM > loadgo ./1-print.go
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/nspcc-dev/neo-go/pkg/compiler.codeGen(0xc000047300)
	github.com/nspcc-dev/neo-go/pkg/compiler/codegen.go:2188 +0x60c
github.com/nspcc-dev/neo-go/pkg/compiler.CompileWithOptions({0xc000047300, 0xf66c92}, {0x0, 0x0}, 0xc0003a0000)
	github.com/nspcc-dev/neo-go/pkg/compiler/compiler.go:218 +0x65
github.com/nspcc-dev/neo-go/pkg/vm/cli.handleLoadGo(0xc0000f5340)
	github.com/nspcc-dev/neo-go/pkg/vm/cli/cli.go:480 +0x1a5
github.com/urfave/cli.HandleAction({0xde74a0, 0x10d61d0}, 0x6)
	github.com/urfave/cli@v1.22.5/app.go:524 +0xa8
github.com/urfave/cli.Command.Run({{0xf632f0, 0x6}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0xf9915b, 0x38}, {0xf6a57b, ...}, ...}, ...)
	github.com/urfave/cli@v1.22.5/command.go:173 +0x652
github.com/urfave/cli.(*App).Run(0xc0002c2000, {0xc00036c330, 0x3, 0x3})
	github.com/urfave/cli@v1.22.5/app.go:277 +0x705
github.com/nspcc-dev/neo-go/pkg/vm/cli.(*VMCLI).Run(0xc000290890)
	github.com/nspcc-dev/neo-go/pkg/vm/cli/cli.go:694 +0x317
github.com/nspcc-dev/neo-go/cli/vm.startVMPrompt(0xc0001b9e40)
	github.com/nspcc-dev/neo-go/cli/vm/vm.go:29 +0x92
github.com/urfave/cli.HandleAction({0xde74a0, 0x10d5d10}, 0x2)
	github.com/urfave/cli@v1.22.5/app.go:524 +0xa8
github.com/urfave/cli.Command.Run({{0xf60a2f, 0x2}, {0x0, 0x0}, {0x0, 0x0, 0x0}, {0xf7880b, 0x19}, {0x0, ...}, ...}, ...)
	github.com/urfave/cli@v1.22.5/command.go:173 +0x652
github.com/urfave/cli.(*App).Run(0xc0001c8fc0, {0xc000116020, 0x2, 0x2})
	github.com/urfave/cli@v1.22.5/app.go:277 +0x705
main.main()
	./main.go:21 +0x33
```
2022-08-17 11:29:28 +03:00
Roman Khimov
f7c5ab4f43 state: check for array length in (*Contract).FromStackItem
Panicing here is not appropriate.
2022-08-16 17:19:47 +03:00
Anna Shaleva
07ee7f7e12 compiler: allow multi-return variables declaration
Problem: an attempt to compile the following code leads to a runtime
panic:
```
package foo
var a, b = f()
func Main() int {
	return a + b
}
func f() (int, int) {
	return 1, 2
}
```

```
panic: runtime error: index out of range [1] with length 1 [recovered]
	panic: runtime error: index out of range [1] with length 1

goroutine 22 [running]:
testing.tRunner.func1.2({0xa341c0, 0xc0001647f8})
	/usr/local/go/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1212 +0x218
panic({0xa341c0, 0xc0001647f8})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).Visit(0xc0001623c0, {0xc75520, 0xc000155d80})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:591 +0x6559
go/ast.Walk({0xc6c4e0, 0xc0001623c0}, {0xc75520, 0xc000155d80})
	/usr/local/go/src/go/ast/walk.go:50 +0x5f
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertGlobals.func1({0xc75520, 0xc000155d80})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:359 +0x70
go/ast.inspector.Visit(0xc000229740, {0xc75520, 0xc000155d80})
	/usr/local/go/src/go/ast/walk.go:375 +0x31
go/ast.Walk({0xc6d920, 0xc000229740}, {0xc75520, 0xc000155d80})
	/usr/local/go/src/go/ast/walk.go:50 +0x5f
go/ast.walkDeclList({0xc6d920, 0xc000229740}, {0xc000155e80, 0x3, 0x120})
	/usr/local/go/src/go/ast/walk.go:36 +0x87
go/ast.Walk({0xc6d920, 0xc000229740}, {0xc75458, 0xc000156c80})
	/usr/local/go/src/go/ast/walk.go:355 +0x15c5
go/ast.Inspect(...)
	/usr/local/go/src/go/ast/walk.go:387
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertGlobals(0xc0001623c0, 0xc000156c80, 0xc000254280)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:354 +0x71
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).traverseGlobals.func2(0xc000254280)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/analysis.go:86 +0x16e
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).ForEachPackage(0xc0001623c0, 0xc000191b98)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/compiler.go:93 +0xc6
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).traverseGlobals(0xc0001623c0)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/analysis.go:82 +0x22c
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).compile(0xc0001623c0, 0xc000274d20, 0x1)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:2118 +0x17c
github.com/nspcc-dev/neo-go/pkg/compiler.codeGen(0xc000274d20)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/codegen.go:2191 +0x353
github.com/nspcc-dev/neo-go/pkg/compiler.CompileWithOptions({0xa6f39a, 0xc00023cee0}, {0xc6d240, 0xc00024a460}, 0x0)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/compiler.go:218 +0x65
github.com/nspcc-dev/neo-go/pkg/compiler_test.vmAndCompileInterop(0x5648df, {0xa9989f, 0x7d})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/vm_test.go:75 +0x113
github.com/nspcc-dev/neo-go/pkg/compiler_test.eval(0xc00024a440, {0xa9989f, 0x129f366e}, {0xa68880, 0xc00024a440})
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/vm_test.go:36 +0x2d
github.com/nspcc-dev/neo-go/pkg/compiler_test.TestGenDeclWithMultiRet.func2(0x4079f9)
	/home/anna/Documents/GitProjects/nspcc-dev/neo-go/pkg/compiler/global_test.go:36 +0x4f
testing.tRunner(0xc00022e9c0, 0xbce760)
	/usr/local/go/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1306 +0x35a
```

Solution:

Allow using multi-return function calls as general variable declaration
value. It was supported for assignment statements, so do the same for
*ast.GenDecl if it's a variable under the hood.
2022-08-16 15:33:44 +03:00
Roman Khimov
f8857c5ebe
Merge pull request #2643 from nspcc-dev/policy-contract-rpc-wrapper
Policy/GAS/Designation contracts RPC wrappers
2022-08-16 13:08:34 +03:00
Roman Khimov
5d5455312a rpcclient: add policy package for the PolicyContract contract
And test it with the RPC server.

Notice that getters still return int64 instead of *big.Int, that's because
these values are very limited and technically could even fit into an int (but
that seems to be too dangerous to use for long-term compatibility).
2022-08-16 12:43:25 +03:00
Roman Khimov
ee72b2fa29 rpcclient: add gas package for the GAS contract
Test it with the RPC server.
2022-08-16 12:43:25 +03:00
Roman Khimov
ee84a4ab32 rpcclient: add rolemgmt pkg for RoleManagement contract
And test it with RPC server.
2022-08-16 12:43:25 +03:00
Roman Khimov
a1a5db8fcd state: add more convenient method to get native contract hashes 2022-08-15 10:54:29 +03:00
Roman Khimov
bc9b5d6976 ROADMAP: update wrt 0.99.2 release 2022-08-12 19:11:23 +03:00
Roman Khimov
10b3c5d157 CHANGELOG: release 0.99.2 2022-08-12 18:48:02 +03:00
Roman Khimov
db12341755
Merge pull request #2642 from nspcc-dev/rpcclient-nep17
NEP-17 RPC client
2022-08-12 18:27:51 +03:00
Roman Khimov
c967005216 rpcclient: add deprecation notices
And fix test code using old APIs to pass linter checks.
2022-08-12 18:21:02 +03:00
Roman Khimov
be74cc6b55 cli: use nep17 wrapper to implement commands 2022-08-12 18:21:02 +03:00
Roman Khimov
309358c85b rpcclient: add new NEP-17 wrapper 2022-08-12 18:21:02 +03:00