2018-03-14 09:36:59 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
2020-12-07 09:52:19 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2020-07-09 09:57:24 +00:00
|
|
|
"math/big"
|
2019-09-09 14:54:38 +00:00
|
|
|
"net"
|
2020-12-07 09:52:19 +00:00
|
|
|
"sync"
|
2019-09-25 16:54:31 +00:00
|
|
|
"sync/atomic"
|
2018-03-14 09:36:59 +00:00
|
|
|
"testing"
|
2020-12-07 09:52:19 +00:00
|
|
|
"time"
|
2018-03-14 09:36:59 +00:00
|
|
|
|
2020-03-25 15:30:21 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2020-12-07 09:52:19 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
2020-11-27 10:55:48 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
2020-08-20 08:02:11 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2020-05-22 09:59:18 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/capability"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
2020-11-11 15:43:28 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
2020-12-07 09:52:19 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-12-30 07:43:05 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
2018-03-14 09:36:59 +00:00
|
|
|
)
|
|
|
|
|
2019-09-25 16:54:31 +00:00
|
|
|
type testChain struct {
|
2020-12-07 09:52:19 +00:00
|
|
|
config.ProtocolConfiguration
|
|
|
|
*mempool.Pool
|
2020-11-27 10:55:48 +00:00
|
|
|
blocksCh []chan<- *block.Block
|
|
|
|
blockheight uint32
|
|
|
|
poolTx func(*transaction.Transaction) error
|
|
|
|
poolTxWithData func(*transaction.Transaction, interface{}, *mempool.Pool) error
|
|
|
|
blocks map[util.Uint256]*block.Block
|
|
|
|
hdrHashes map[uint32]util.Uint256
|
|
|
|
txs map[util.Uint256]*transaction.Transaction
|
|
|
|
verifyWitnessF func() error
|
|
|
|
maxVerificationGAS int64
|
|
|
|
notaryContractScriptHash util.Uint160
|
|
|
|
notaryDepositExpiration uint32
|
|
|
|
postBlock []func(blockchainer.Blockchainer, *mempool.Pool, *block.Block)
|
|
|
|
utilityTokenBalance *big.Int
|
2019-09-25 16:54:31 +00:00
|
|
|
}
|
2018-03-14 09:36:59 +00:00
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func newTestChain() *testChain {
|
|
|
|
return &testChain{
|
2020-11-27 10:55:48 +00:00
|
|
|
Pool: mempool.New(10, 0),
|
|
|
|
poolTx: func(*transaction.Transaction) error { return nil },
|
|
|
|
poolTxWithData: func(*transaction.Transaction, interface{}, *mempool.Pool) error { return nil },
|
|
|
|
blocks: make(map[util.Uint256]*block.Block),
|
|
|
|
hdrHashes: make(map[uint32]util.Uint256),
|
|
|
|
txs: make(map[util.Uint256]*transaction.Transaction),
|
|
|
|
ProtocolConfiguration: config.ProtocolConfiguration{P2PNotaryRequestPayloadPoolSize: 10},
|
2020-12-07 09:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) putBlock(b *block.Block) {
|
|
|
|
chain.blocks[b.Hash()] = b
|
|
|
|
chain.hdrHashes[b.Index] = b.Hash()
|
|
|
|
atomic.StoreUint32(&chain.blockheight, b.Index)
|
2020-02-18 17:16:38 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) putHeader(b *block.Block) {
|
|
|
|
chain.hdrHashes[b.Index] = b.Hash()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) putTx(tx *transaction.Transaction) {
|
|
|
|
chain.txs[tx.Hash()] = tx
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-11-27 10:55:48 +00:00
|
|
|
|
|
|
|
func (chain *testChain) IsTxStillRelevant(t *transaction.Transaction, txpool *mempool.Pool, isPartialTx bool) bool {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) GetNotaryDepositExpiration(acc util.Uint160) uint32 {
|
|
|
|
if chain.notaryDepositExpiration != 0 {
|
|
|
|
return chain.notaryDepositExpiration
|
|
|
|
}
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) GetNotaryContractScriptHash() util.Uint160 {
|
|
|
|
if !chain.notaryContractScriptHash.Equals(util.Uint160{}) {
|
|
|
|
return chain.notaryContractScriptHash
|
|
|
|
}
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) GetNotaryBalance(acc util.Uint160) *big.Int {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) GetPolicer() blockchainer.Policer {
|
|
|
|
return chain
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) GetMaxVerificationGAS() int64 {
|
|
|
|
if chain.maxVerificationGAS != 0 {
|
|
|
|
return chain.maxVerificationGAS
|
|
|
|
}
|
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(bc blockchainer.Blockchainer, t *transaction.Transaction, data interface{}) error) error {
|
|
|
|
return chain.poolTxWithData(t, data, mp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (chain *testChain) RegisterPostBlock(f func(blockchainer.Blockchainer, *mempool.Pool, *block.Block)) {
|
|
|
|
chain.postBlock = append(chain.postBlock, f)
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetConfig() config.ProtocolConfiguration {
|
|
|
|
return chain.ProtocolConfiguration
|
|
|
|
}
|
|
|
|
func (chain *testChain) CalculateClaimable(util.Uint160, uint32) (*big.Int, error) {
|
2020-02-25 13:15:17 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2019-02-20 17:39:32 +00:00
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) FeePerByte() int64 {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) P2PSigExtensionsEnabled() bool {
|
2020-11-27 10:55:48 +00:00
|
|
|
return true
|
2020-10-15 11:45:29 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetMaxBlockSystemFee() int64 {
|
2020-08-03 16:27:32 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetMaxBlockSize() uint32 {
|
2020-08-03 16:27:32 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) AddHeaders(...*block.Header) error {
|
2019-02-20 17:39:32 +00:00
|
|
|
panic("TODO")
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-01-14 12:32:07 +00:00
|
|
|
func (chain *testChain) AddBlock(block *block.Block) error {
|
2020-12-07 09:52:19 +00:00
|
|
|
if block.Index == atomic.LoadUint32(&chain.blockheight)+1 {
|
|
|
|
chain.putBlock(block)
|
2019-09-25 16:54:31 +00:00
|
|
|
}
|
|
|
|
return nil
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-05-29 14:20:00 +00:00
|
|
|
func (chain *testChain) AddStateRoot(r *state.MPTRoot) error {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
2019-09-25 16:54:31 +00:00
|
|
|
func (chain *testChain) BlockHeight() uint32 {
|
|
|
|
return atomic.LoadUint32(&chain.blockheight)
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2019-11-07 17:47:48 +00:00
|
|
|
func (chain *testChain) Close() {
|
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) HeaderHeight() uint32 {
|
|
|
|
return atomic.LoadUint32(&chain.blockheight)
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetAppExecResults(hash util.Uint256, trig trigger.Type) ([]state.AppExecResult, error) {
|
2020-02-21 14:56:28 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetBlock(hash util.Uint256) (*block.Block, error) {
|
|
|
|
if b, ok := chain.blocks[hash]; ok {
|
|
|
|
return b, nil
|
|
|
|
}
|
|
|
|
return nil, errors.New("not found")
|
2018-03-23 20:36:59 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetCommittee() (keys.PublicKeys, error) {
|
2020-09-21 12:34:04 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetContractState(hash util.Uint160) *state.Contract {
|
2019-10-11 11:22:53 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetContractScriptHash(id int32) (util.Uint160, error) {
|
2020-07-28 13:36:47 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetNativeContractScriptHash(name string) (util.Uint160, error) {
|
2020-09-25 09:40:57 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetHeaderHash(n int) util.Uint256 {
|
|
|
|
return chain.hdrHashes[uint32(n)]
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetHeader(hash util.Uint256) (*block.Header, error) {
|
|
|
|
b, err := chain.GetBlock(hash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Header(), nil
|
2019-02-20 17:39:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetNextBlockValidators() ([]*keys.PublicKey, error) {
|
2020-07-11 10:10:57 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) ForEachNEP17Transfer(util.Uint160, func(*state.NEP17Transfer) (bool, error)) error {
|
2020-03-05 12:16:03 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetNEP17Balances(util.Uint160) *state.NEP17Balances {
|
2020-03-11 15:22:46 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetValidators() ([]*keys.PublicKey, error) {
|
2019-11-11 15:25:28 +00:00
|
|
|
panic("TODO")
|
2020-08-05 08:30:14 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetStandByCommittee() keys.PublicKeys {
|
2020-08-05 08:30:14 +00:00
|
|
|
panic("TODO")
|
2019-11-11 15:25:28 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetStandByValidators() keys.PublicKeys {
|
2020-03-30 08:16:53 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetEnrollments() ([]state.Validator, error) {
|
2020-03-05 14:48:30 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetStateProof(util.Uint256, []byte) ([][]byte, error) {
|
2020-06-04 08:59:22 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetStateRoot(height uint32) (*state.MPTRootState, error) {
|
2020-05-29 14:20:00 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetStorageItem(id int32, key []byte) *state.StorageItem {
|
2019-10-11 11:08:21 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetTestVM(tx *transaction.Transaction, b *block.Block) *vm.VM {
|
2019-10-29 15:31:39 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetStorageItems(id int32) (map[string]*state.StorageItem, error) {
|
2019-10-11 11:08:21 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) CurrentHeaderHash() util.Uint256 {
|
2018-03-14 09:36:59 +00:00
|
|
|
return util.Uint256{}
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) CurrentBlockHash() util.Uint256 {
|
2018-03-14 09:36:59 +00:00
|
|
|
return util.Uint256{}
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) HasBlock(h util.Uint256) bool {
|
|
|
|
_, ok := chain.blocks[h]
|
|
|
|
return ok
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) HasTransaction(h util.Uint256) bool {
|
|
|
|
_, ok := chain.txs[h]
|
|
|
|
return ok
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetTransaction(h util.Uint256) (*transaction.Transaction, uint32, error) {
|
|
|
|
if tx, ok := chain.txs[h]; ok {
|
|
|
|
return tx, 1, nil
|
|
|
|
}
|
|
|
|
return nil, 0, errors.New("not found")
|
2019-10-11 11:16:53 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetMemPool() *mempool.Pool {
|
|
|
|
return chain.Pool
|
Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'
* Added new files:
* Added new method: CompareTo
* Fixed empty Slice case
* Added new methods: LessThan, GreaterThan, Equal, CompareTo
* Added new method: InputIntersection
* Added MaxTransactionSize, GroupOutputByAssetID
* Added ned method: ScriptHash
* Added new method: IsDoubleSpend
* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method
* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool
* Added new methods: RelayTxn, RelayDirectly
* Fixed tests
* Implemented RPC server method sendrawtransaction
* Refactor getrawtransaction, sendrawtransaction in separate methods
* Moved 'secondsPerBlock' to config file
* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code
* Fixed minor issues related to
1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring CompareTo method in uint256.go
* Fixed small issues
* Use sync.RWMutex instead of sync.Mutex
* Refined (R)Lock/(R)Unlock
* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetGoverningTokenBalance(acc util.Uint160) (*big.Int, uint32) {
|
2020-06-01 20:27:03 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) GetUtilityTokenBalance(uint160 util.Uint160) *big.Int {
|
2020-11-27 10:55:48 +00:00
|
|
|
if chain.utilityTokenBalance != nil {
|
|
|
|
return chain.utilityTokenBalance
|
|
|
|
}
|
2020-05-18 08:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) PoolTx(tx *transaction.Transaction, _ ...*mempool.Pool) error {
|
|
|
|
return chain.poolTx(tx)
|
2020-02-04 15:43:21 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) SubscribeForBlocks(ch chan<- *block.Block) {
|
|
|
|
chain.blocksCh = append(chain.blocksCh, ch)
|
2020-05-12 14:20:41 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) SubscribeForExecutions(ch chan<- *state.AppExecResult) {
|
2020-05-12 14:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) SubscribeForNotifications(ch chan<- *state.NotificationEvent) {
|
2020-05-12 14:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) SubscribeForTransactions(ch chan<- *transaction.Transaction) {
|
2020-05-12 14:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) VerifyTx(*transaction.Transaction) error {
|
Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'
* Added new files:
* Added new method: CompareTo
* Fixed empty Slice case
* Added new methods: LessThan, GreaterThan, Equal, CompareTo
* Added new method: InputIntersection
* Added MaxTransactionSize, GroupOutputByAssetID
* Added ned method: ScriptHash
* Added new method: IsDoubleSpend
* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method
* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool
* Added new methods: RelayTxn, RelayDirectly
* Fixed tests
* Implemented RPC server method sendrawtransaction
* Refactor getrawtransaction, sendrawtransaction in separate methods
* Moved 'secondsPerBlock' to config file
* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code
* Fixed minor issues related to
1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring CompareTo method in uint256.go
* Fixed small issues
* Use sync.RWMutex instead of sync.Mutex
* Refined (R)Lock/(R)Unlock
* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-11-27 10:55:48 +00:00
|
|
|
func (chain *testChain) VerifyWitness(util.Uint160, crypto.Verifiable, *transaction.Witness, int64) error {
|
|
|
|
if chain.verifyWitnessF != nil {
|
|
|
|
return chain.verifyWitnessF()
|
|
|
|
}
|
2020-08-20 08:02:11 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
Implement rpc server method: sendrawtransaction (#174)
* Added new config attributes: 'SecondsPerBlock','LowPriorityThreshold'
* Added new files:
* Added new method: CompareTo
* Fixed empty Slice case
* Added new methods: LessThan, GreaterThan, Equal, CompareTo
* Added new method: InputIntersection
* Added MaxTransactionSize, GroupOutputByAssetID
* Added ned method: ScriptHash
* Added new method: IsDoubleSpend
* Refactor blockchainer, Added Feer interface, Verify and GetMemPool method
* 1) Added MemPool
2) Added new methods to satisfy the blockchainer interface: IsLowPriority, Verify, GetMemPool
* Added new methods: RelayTxn, RelayDirectly
* Fixed tests
* Implemented RPC server method sendrawtransaction
* Refactor getrawtransaction, sendrawtransaction in separate methods
* Moved 'secondsPerBlock' to config file
* Implemented Kim suggestions:
1) Fixed data race issues
2) refactor Verify method
3) Get rid of unused InputIntersection method due to refactoring Verify method
4) Fixed bug in https://github.com/CityOfZion/neo-go/pull/174#discussion_r264108135
5) minor simplications of the code
* Fixed minor issues related to
1) space
2) getter methods do not need pointer on the receiver
3) error message
4) refactoring CompareTo method in uint256.go
* Fixed small issues
* Use sync.RWMutex instead of sync.Mutex
* Refined (R)Lock/(R)Unlock
* return error instead of bool in Verify methods
2019-03-20 12:30:05 +00:00
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) UnsubscribeFromBlocks(ch chan<- *block.Block) {
|
|
|
|
for i, c := range chain.blocksCh {
|
|
|
|
if c == ch {
|
|
|
|
if i < len(chain.blocksCh) {
|
|
|
|
copy(chain.blocksCh[i:], chain.blocksCh[i+1:])
|
|
|
|
}
|
|
|
|
chain.blocksCh = chain.blocksCh[:len(chain.blocksCh)]
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 14:20:41 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult) {
|
2020-05-12 14:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) UnsubscribeFromNotifications(ch chan<- *state.NotificationEvent) {
|
2020-05-12 14:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (chain *testChain) UnsubscribeFromTransactions(ch chan<- *transaction.Transaction) {
|
2020-05-12 14:20:41 +00:00
|
|
|
panic("TODO")
|
|
|
|
}
|
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
type testDiscovery struct {
|
|
|
|
sync.Mutex
|
|
|
|
bad []string
|
|
|
|
good []string
|
|
|
|
connected []string
|
|
|
|
unregistered []string
|
|
|
|
backfill []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestDiscovery([]string, time.Duration, Transporter) Discoverer { return new(testDiscovery) }
|
2018-03-14 09:36:59 +00:00
|
|
|
|
2020-12-07 09:52:19 +00:00
|
|
|
func (d *testDiscovery) BackFill(addrs ...string) {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
d.backfill = append(d.backfill, addrs...)
|
|
|
|
}
|
|
|
|
func (d *testDiscovery) Close() {}
|
|
|
|
func (d *testDiscovery) PoolCount() int { return 0 }
|
|
|
|
func (d *testDiscovery) RegisterBadAddr(addr string) {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
d.bad = append(d.bad, addr)
|
|
|
|
}
|
|
|
|
func (d *testDiscovery) RegisterGoodAddr(string, capability.Capabilities) {}
|
|
|
|
func (d *testDiscovery) RegisterConnectedAddr(addr string) {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
d.connected = append(d.connected, addr)
|
|
|
|
}
|
|
|
|
func (d *testDiscovery) UnregisterConnectedAddr(addr string) {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
d.unregistered = append(d.unregistered, addr)
|
|
|
|
}
|
|
|
|
func (d *testDiscovery) UnconnectedPeers() []string {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
return d.unregistered
|
|
|
|
}
|
|
|
|
func (d *testDiscovery) RequestRemote(n int) {}
|
|
|
|
func (d *testDiscovery) BadPeers() []string {
|
|
|
|
d.Lock()
|
|
|
|
defer d.Unlock()
|
|
|
|
return d.bad
|
|
|
|
}
|
|
|
|
func (d *testDiscovery) GoodPeers() []AddressWithCapabilities { return []AddressWithCapabilities{} }
|
2018-03-14 09:36:59 +00:00
|
|
|
|
|
|
|
var defaultMessageHandler = func(t *testing.T, msg *Message) {}
|
|
|
|
|
|
|
|
type localPeer struct {
|
2019-09-09 14:54:38 +00:00
|
|
|
netaddr net.TCPAddr
|
2020-01-21 14:26:08 +00:00
|
|
|
server *Server
|
2018-03-14 09:36:59 +00:00
|
|
|
version *payload.Version
|
2020-01-17 10:17:19 +00:00
|
|
|
lastBlockIndex uint32
|
2019-09-13 12:43:22 +00:00
|
|
|
handshaked bool
|
2020-05-22 09:17:17 +00:00
|
|
|
isFullNode bool
|
2018-03-14 09:36:59 +00:00
|
|
|
t *testing.T
|
|
|
|
messageHandler func(t *testing.T, msg *Message)
|
2020-01-20 16:02:19 +00:00
|
|
|
pingSent int
|
2020-11-25 10:34:38 +00:00
|
|
|
getAddrSent int
|
2020-12-07 09:52:19 +00:00
|
|
|
droppedWith atomic.Value
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 14:26:08 +00:00
|
|
|
func newLocalPeer(t *testing.T, s *Server) *localPeer {
|
2019-09-09 14:54:38 +00:00
|
|
|
naddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
2018-03-14 09:36:59 +00:00
|
|
|
return &localPeer{
|
|
|
|
t: t,
|
2020-01-21 14:26:08 +00:00
|
|
|
server: s,
|
2019-09-09 14:54:38 +00:00
|
|
|
netaddr: *naddr,
|
2018-03-14 09:36:59 +00:00
|
|
|
messageHandler: defaultMessageHandler,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 07:55:21 +00:00
|
|
|
func (p *localPeer) RemoteAddr() net.Addr {
|
|
|
|
return &p.netaddr
|
|
|
|
}
|
|
|
|
func (p *localPeer) PeerAddr() net.Addr {
|
2019-09-09 14:54:38 +00:00
|
|
|
return &p.netaddr
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
2020-12-07 09:52:19 +00:00
|
|
|
func (p *localPeer) StartProtocol() {}
|
|
|
|
func (p *localPeer) Disconnect(err error) {
|
|
|
|
if p.droppedWith.Load() == nil {
|
|
|
|
p.droppedWith.Store(err)
|
|
|
|
}
|
|
|
|
fmt.Println("peer dropped:", err)
|
|
|
|
p.server.unregister <- peerDrop{p, err}
|
|
|
|
}
|
2020-01-16 18:16:31 +00:00
|
|
|
|
|
|
|
func (p *localPeer) EnqueueMessage(msg *Message) error {
|
|
|
|
b, err := msg.Bytes()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return p.EnqueuePacket(b)
|
|
|
|
}
|
|
|
|
func (p *localPeer) EnqueuePacket(m []byte) error {
|
|
|
|
return p.EnqueueHPPacket(m)
|
|
|
|
}
|
2020-01-23 16:40:40 +00:00
|
|
|
func (p *localPeer) EnqueueP2PMessage(msg *Message) error {
|
|
|
|
return p.EnqueueMessage(msg)
|
|
|
|
}
|
|
|
|
func (p *localPeer) EnqueueP2PPacket(m []byte) error {
|
|
|
|
return p.EnqueueHPPacket(m)
|
|
|
|
}
|
2020-01-16 18:16:31 +00:00
|
|
|
func (p *localPeer) EnqueueHPPacket(m []byte) error {
|
2020-12-07 09:52:19 +00:00
|
|
|
msg := &Message{Network: netmode.UnitTestNet}
|
2020-01-16 18:16:31 +00:00
|
|
|
r := io.NewBinReaderFromBuf(m)
|
|
|
|
err := msg.Decode(r)
|
|
|
|
if err == nil {
|
|
|
|
p.messageHandler(p.t, msg)
|
|
|
|
}
|
2018-04-13 10:14:08 +00:00
|
|
|
return nil
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|
|
|
|
func (p *localPeer) Version() *payload.Version {
|
|
|
|
return p.version
|
|
|
|
}
|
2020-01-17 10:17:19 +00:00
|
|
|
func (p *localPeer) LastBlockIndex() uint32 {
|
|
|
|
return p.lastBlockIndex
|
|
|
|
}
|
2019-09-13 12:43:22 +00:00
|
|
|
func (p *localPeer) HandleVersion(v *payload.Version) error {
|
2018-04-13 10:14:08 +00:00
|
|
|
p.version = v
|
2019-09-13 12:43:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-01-21 14:26:08 +00:00
|
|
|
func (p *localPeer) SendVersion() error {
|
2020-05-22 09:17:17 +00:00
|
|
|
m, err := p.server.getVersionMsg()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-01-16 18:16:31 +00:00
|
|
|
_ = p.EnqueueMessage(m)
|
|
|
|
return nil
|
2019-09-13 12:43:22 +00:00
|
|
|
}
|
|
|
|
func (p *localPeer) SendVersionAck(m *Message) error {
|
2020-01-16 18:16:31 +00:00
|
|
|
_ = p.EnqueueMessage(m)
|
|
|
|
return nil
|
2019-09-13 12:43:22 +00:00
|
|
|
}
|
|
|
|
func (p *localPeer) HandleVersionAck() error {
|
|
|
|
p.handshaked = true
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-27 09:44:05 +00:00
|
|
|
func (p *localPeer) SendPing(m *Message) error {
|
2020-01-20 16:02:19 +00:00
|
|
|
p.pingSent++
|
2020-01-27 09:44:05 +00:00
|
|
|
_ = p.EnqueueMessage(m)
|
2020-01-20 16:02:19 +00:00
|
|
|
return nil
|
2020-01-17 10:17:19 +00:00
|
|
|
}
|
2020-08-14 13:22:15 +00:00
|
|
|
func (p *localPeer) HandlePing(ping *payload.Ping) error {
|
|
|
|
p.lastBlockIndex = ping.LastBlockIndex
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-20 16:02:19 +00:00
|
|
|
func (p *localPeer) HandlePong(pong *payload.Ping) error {
|
|
|
|
p.lastBlockIndex = pong.LastBlockIndex
|
|
|
|
p.pingSent--
|
|
|
|
return nil
|
2020-01-17 10:17:19 +00:00
|
|
|
}
|
2019-09-13 12:43:22 +00:00
|
|
|
|
|
|
|
func (p *localPeer) Handshaked() bool {
|
|
|
|
return p.handshaked
|
2018-04-13 10:14:08 +00:00
|
|
|
}
|
2018-03-14 09:36:59 +00:00
|
|
|
|
2020-05-22 09:17:17 +00:00
|
|
|
func (p *localPeer) IsFullNode() bool {
|
|
|
|
return p.isFullNode
|
|
|
|
}
|
|
|
|
|
2020-11-25 10:34:38 +00:00
|
|
|
func (p *localPeer) AddGetAddrSent() {
|
|
|
|
p.getAddrSent++
|
|
|
|
}
|
|
|
|
func (p *localPeer) CanProcessAddr() bool {
|
|
|
|
p.getAddrSent--
|
|
|
|
return p.getAddrSent >= 0
|
|
|
|
}
|
|
|
|
|
2020-05-22 09:17:17 +00:00
|
|
|
func newTestServer(t *testing.T, serverConfig ServerConfig) *Server {
|
2020-12-07 09:52:19 +00:00
|
|
|
s, err := newServerFromConstructors(serverConfig, newTestChain(), zaptest.NewLogger(t),
|
|
|
|
newFakeTransp, newFakeConsensus, newTestDiscovery)
|
|
|
|
require.NoError(t, err)
|
2020-05-22 09:17:17 +00:00
|
|
|
return s
|
2018-03-14 09:36:59 +00:00
|
|
|
}
|