Commit graph

360 commits

Author SHA1 Message Date
Roman Khimov
3e2b490025 mempool: rework inputs verification, check Claim txes
Use more efficient check for Input and also check Claims to avoid double
claiming.
2020-02-27 13:43:35 +03:00
Roman Khimov
f329de73e8 mempool: fix Remove bug (dropping wrong tx!)
Uncovered by TestMemPoolAddRemoveWithInputsAndClaims (to be added later)
2020-02-27 13:43:35 +03:00
Roman Khimov
7d59fa0066
Merge pull request #696 from nspcc-dev/tx-verification-fixes
Claim and enrollment TX verification fixes
2020-02-27 12:45:36 +03:00
Roman Khimov
00d199ed85 core: fix NetworkFee calculation
Add doesn't change the variable state. Thanks to GolangCI for catching this.
2020-02-27 12:32:56 +03:00
Roman Khimov
7bea6e043e core: add double claim verification check 2020-02-27 12:32:56 +03:00
Roman Khimov
29586f2aa7 core: add duplicate Claim verification check
Refactor HaveInputsDuplicate() out of the core and Blockchain, it doesn't
depend on the Blockchain state. Make it more efficient.
2020-02-27 12:32:56 +03:00
Roman Khimov
9b1ad40273 core: drop GetScriptHashesForVerifyingClaim, fix Claim's ScriptHash getter
Claim transactions should _add_ claims scripthashes to the standard list, not
replace them. And this code is actually very reusable.
2020-02-27 12:32:56 +03:00
Roman Khimov
9f7018503a core/transaction: use new transaction.InOut for References
We don't need a map here, use simpler structures.
2020-02-27 12:00:03 +03:00
Roman Khimov
80de208a68 transaction: unbind GroupInputsByPrevHash from Transaction
Which allows to use it for ClaimTX. Make it also a bit more efficient as maps
are expensive.
2020-02-27 12:00:03 +03:00
Roman Khimov
b1b184f77f
Merge pull request #692 from nspcc-dev/persist-timer-fix
core: reschedule the next persist in a second from previous one
2020-02-26 10:34:40 +03:00
Roman Khimov
c258adb532 core: move spent coin management out of the inner storeBlock loop
prevHash == input.PrevHash, so make less DB accesses and more real work. Fix
some bugs along the way:
 * spentCoins structure may already be present in the DB when persisting TX,
   there is nothing wrong with that and we shouldn't overwrite it
 * it's only used for NEO and only to check for claim validity. Thus, when
   processing claim tx the corresponding spentCoins should always be present
   in the DB
2020-02-25 17:21:09 +03:00
Roman Khimov
36c6b6af14 core: put unspents get/put one loop above in storeBlock
Everywhere in this code prevHash == input.PrevHash, thus we can easily move
some common code out of the loop saving on DB accesses and
serialization/deserialization.
2020-02-24 18:53:10 +03:00
Roman Khimov
5c9681508b transaction: strip off a layer of redirection from ClaimTX.Claims
We don't need a pointer here and this change makes this field compatible with
Transaction.Inputs which is useful in many scenarios.
2020-02-24 18:22:27 +03:00
Roman Khimov
ed9e9e8590 storage: add locking into (*MemoryStore).Seek
It was missing there.
2020-02-24 17:51:50 +03:00
Roman Khimov
b49808b766 core: reschedule the next persist in a second from previous one
It makes little sense queueing up several persistence goroutines (or actually
even running them concurrently).
2020-02-24 17:17:25 +03:00
Roman Khimov
d5e6028c13 core: add validator public key into the list of hashes to verify
That should be done for Enrollment transactions.
2020-02-21 20:04:16 +03:00
Roman Khimov
a903147b60 keys: rename Signature to GetScriptHash, make it return Uint160
Signature itself wasn't used at all and its name is very misleading, Uint160
script hash is way more useful.
2020-02-19 12:19:03 +03:00
Roman Khimov
eb11e5fb11 core: implement basic policying support, fix #370
Implement mempool and consensus block creation policies, almost the same as
SimplePolicy plugin for C# node provides with two caveats:
 * HighPriorityTxType is not configured and hardcoded to ClaimType
 * BlockedAccounts are not supported

Other than that it allows us to run successfuly as testnet CN, previously our
proposals were rejected because we were proposing blocks with oversized
transactions (that are rejected by PoolTx() now).

Mainnet and testnet configuration files are updated accordingly, but privnet
is left as is with no limits.

Configuration is currently attached to the Blockchain and so is the code that
does policying, it may be moved somewhere in the future, but it works for
now.
2020-02-19 12:19:02 +03:00
Roman Khimov
22f5667530 mempool: return fee along with tx when requesting tx
Users of GetVerifiedTransactions() don't want to recalculate tx fee and it's
nice to have it returned from TryGetValue() also sometimes.
2020-02-19 12:19:02 +03:00
Roman Khimov
06daeb44f3 core: make IsLowPriority work with pre-calculated fee
Don't recalculate it again and again.
2020-02-19 12:19:02 +03:00
Roman Khimov
a4294f4b5f core: export UtilityTokenID and GoverningTokenID
Both are very useful outside of the core, this change also makes respective
transactions initialize with the package as they don't depend on any kind of
input and it makes no sense recreating them again and again on every use.
2020-02-19 12:13:27 +03:00
Roman Khimov
b41a5239c6 core: always sort the result of GetValidators
It wasn't sorted when all validators were elected. There is also no need to do
`Unique()` on the result because validators are distinguished by the key, so
no two registered validators can have the same key.
2020-02-18 20:36:22 +03:00
Evgenii Stratonikov
a2f012e589 core: deploy new smart-contract in test blocks
Also put smart-contract sources in testdata and
add invocation TX with APPCALL and storage.Put.
2020-02-18 11:59:28 +03:00
Anna Shaleva
2b9e63c511 core: add func to generate RPC test data
newRPCTestChain function generates test chain "testblocks.acc" for RPC
tests
2020-02-17 23:54:25 +03:00
Roman Khimov
dfb38e1da1
Merge pull request #649 from nspcc-dev/feature/dump_storage
cli: add possibility to dump storage changes on restore
2020-02-16 23:50:31 +03:00
Roman Khimov
b5453ad24f
Merge pull request #672 from nspcc-dev/fix-sigsegv-on-reference-check
core: deal with bad transaction Inputs
2020-02-14 13:23:42 +03:00
Roman Khimov
0fceaf12d2 core: deal with bad transaction Inputs
They may not really have a reference. Fixes #671.
2020-02-14 09:42:10 +03:00
Roman Khimov
992ccc0b26
Merge pull request #664 from nspcc-dev/sort-validator-keys
core: sort GetValidators() result
2020-02-13 21:46:26 +03:00
Evgeniy Kulikov
8d410a6659
Add JSON tags for RPC response types
- Attribute should have 2 fields (usage, data)
- VOut should have 4 (5) fields (asset, value, address, n)
- Script should have 2 fields (invocation, verification)
2020-02-13 19:06:54 +03:00
Roman Khimov
d4cd134aef core: sort GetValidators() result
As C# node does it. Technically it's only needed for consensus and could be
implemented in the appropriate package, but for better compatibility with C#
node we're better returning it sorted right here.
2020-02-13 17:07:27 +03:00
Roman Khimov
26af9200b0 core: refactor voting processing, fix pending tx subtractions
Deduplicate code and add missing token check for subtractions that are being
done in GetValidators() for pending transactions.
2020-02-13 13:07:34 +03:00
Roman Khimov
c8a248596e core: introduce ValidatorsCount, make a proper count
We were completely lacking ValidatorsCount that is supposed to track the
number of votes with particular count of consensus nodes which in theory can
change the number of active consensus nodes (if it ever to exceed the number
of standby validators), so we were not producing the right count and based on
that not giving the right set of validators.

Fixes #512.
2020-02-13 13:07:34 +03:00
Roman Khimov
357b675090 core: don't choose duplicating standby validators
We may already have chosen some of standby validators, so don't repeat.
2020-02-13 13:07:34 +03:00
Roman Khimov
f9c6a0d77c core: make voting choose the best validators
They need to be sorted in order for voting system to work.
2020-02-13 13:07:34 +03:00
Roman Khimov
2ff7ceb8cf core: properly update validator votes for Account descriptor
ValidatorsCount is not implemented yet, but we need to update validators
properly, adding account's vote to their votes count.
2020-02-13 13:07:34 +03:00
Roman Khimov
8310b76d28 core: properly save votes when processing Account descriptor
They were ignored basically.
2020-02-13 13:07:34 +03:00
Roman Khimov
807309a0de core/state: only drop unregistered non-voted validators
Simple as that: UnregisteredAndHasNoVotes != !RegisteredAndHasVotes

Registered validators should stay in the DB, we might be in the process of
updating votes for them and that starts with subtraction.
2020-02-13 13:07:34 +03:00
Roman Khimov
38d0efc96c core: fix Registered state descriptor processing
It has simple boolean value encoded, no `strconv` needed (it actually chokes
on such input).
2020-02-12 21:27:40 +03:00
Roman Khimov
803fb39bb0 transaction: fix wrong state descriptor serdes
Wrong field order.
2020-02-12 21:23:28 +03:00
Evgenii Stratonikov
0a894db7f8 storage: add Exists flag to KeyValue in batch
Set Exists flag if an item with the specified key was already
present in storage before persisting.
2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
b1d9e1132d cli: dump storage changes into JSON files 2020-02-12 12:16:31 +03:00
Evgenii Stratonikov
fb9af98179 storage: implement GetBatch() to view storage changes
GetBatch returns changes to be persisted.
2020-02-12 12:16:31 +03:00
Roman Khimov
38de2af073
Merge pull request #655 from nspcc-dev/fix-mempool-deadlock-on-reverification
core: get transactions from dao when mempool should not be used
2020-02-11 13:34:23 +03:00
Roman Khimov
292051d8df core: get transactions from dao when mempool should not be used
All of these places deal strictly with the chain and shouldn't ever be
bothered with mempool. It also fixes a deadlock on reverification of
non-standard tx:

1 @ 0x42f62f 0x43fbe9 0x43fbbf 0x43f95d 0x967059 0x966f66 0x972c7c 0x974e13 0x97a5d9 0x97bdf0 0x976147 0x966cc0 0x970f70 0x96c8cb 0x9ba858 0x45ca51
	0x43f95c	sync.runtime_SemacquireMutex+0x3c							/usr/local/go/src/runtime/sema.go:71
	0x967058	sync.(*RWMutex).RLock+0x128								/usr/local/go/src/sync/rwmutex.go:50
	0x966f65	github.com/CityOfZion/neo-go/pkg/core/mempool.(*Pool).TryGetValue+0x35			/go/src/github.com/CityOfZion/neo-go/pkg/core/mempool/mem_pool.go:229
	0x972c7b	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).GetTransaction+0x4b			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:782
	0x974e12	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).References+0x132			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:944
	0x97a5d8	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).GetScriptHashesForVerifying+0x58	/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1410
	0x97bdef	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).verifyTxWitnesses+0x4f		/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1545
	0x976146	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).isTxStillRelevant+0x216		/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:1067
	0x966cbf	github.com/CityOfZion/neo-go/pkg/core/mempool.(*Pool).RemoveStale+0xff			/go/src/github.com/CityOfZion/neo-go/pkg/core/mempool/mem_pool.go:208
	0x970f6f	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).storeBlock+0x2ecf			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:614
	0x96c8ca	github.com/CityOfZion/neo-go/pkg/core.(*Blockchain).AddBlock+0xea			/go/src/github.com/CityOfZion/neo-go/pkg/core/blockchain.go:308
	0x9ba857	github.com/CityOfZion/neo-go/pkg/network.(*blockQueue).run+0x157			/go/src/github.com/CityOfZion/neo-go/pkg/network/blockqueue.go:48
2020-02-10 18:53:22 +03:00
Anna Shaleva
9b03f968b1 core: fixe FreeGasLimit constraint
Lack of FreeGasLimit in privnet leads to gas limit exceeding in case of transactions with small amount of GAS to be used for invoke operation (< real cost of the transaction). Solution: Fixed constraint in case when FreeGasLimit == 0. So now we are able to perform transactions in privnet with FreeGasLimit = 0 for free.
2020-02-10 18:07:19 +03:00
Roman Khimov
9b9adb28c1
Merge pull request #642 from nspcc-dev/feature/emit
vm, compiler: move Emit* functions to a separate package

Closes #449, #534.
2020-02-08 15:56:48 +03:00
Roman Khimov
7ccf7974b6 core: substitute bad notifications with error messages
Tesnet sync failed with:
Feb 07 00:04:19 nodoka neo-go[1747]: 2020-02-07T00:04:19.838+0300        WARN        blockQueue: failed adding block into the blockchain        {"error": "failed to store notifications: not supported", "blockHeight": 713984, "nextIndex": 713985}

because some (not so) smart contract emitted a notification with an
InteropItem inside.
2020-02-07 15:34:59 +03:00
Evgenii Stratonikov
8243a8b3a7 emit: use io.BinWriter instead of bytes.Buffer 2020-02-06 18:45:37 +03:00
Evgenii Stratonikov
4d8a3a359b vm: move Emit* functions to a separate package
Also strip 'Emit' prefix because 'emit' is now
in the package name.
2020-02-06 18:45:37 +03:00
Roman Khimov
ab14a4619d
Merge pull request #647 from nspcc-dev/fix-mempool-and-chain-locking
Fix mempool and chain locking

This allows us easily make 1000 Tx/s in 4-nodes privnet, fixes potential
double spends and improves mempool testing coverage.
2020-02-06 18:43:29 +03:00