2016-11-09 01:01:56 +00:00
|
|
|
// Copyright 2016 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-10-14 03:51:29 +00:00
|
|
|
// This file contains some shares testing functionality, common to multiple
|
|
|
|
// different files and modules being tested.
|
|
|
|
|
|
|
|
package les
|
|
|
|
|
|
|
|
import (
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
"context"
|
2016-10-14 03:51:29 +00:00
|
|
|
"crypto/rand"
|
2020-03-12 10:25:52 +00:00
|
|
|
"fmt"
|
2016-10-14 03:51:29 +00:00
|
|
|
"math/big"
|
2020-03-12 10:25:52 +00:00
|
|
|
"sync/atomic"
|
2016-10-14 03:51:29 +00:00
|
|
|
"testing"
|
2018-08-28 07:08:16 +00:00
|
|
|
"time"
|
2016-10-14 03:51:29 +00:00
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
|
2016-10-14 03:51:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2019-02-26 11:32:48 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/mclock"
|
2017-04-04 22:16:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
"github.com/ethereum/go-ethereum/contracts/checkpointoracle/contract"
|
2016-10-14 03:51:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2018-09-24 12:57:49 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2016-10-14 03:51:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-02-11 12:57:46 +00:00
|
|
|
"github.com/ethereum/go-ethereum/eth"
|
2016-10-14 03:51:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
|
|
"github.com/ethereum/go-ethereum/event"
|
2020-01-07 09:24:21 +00:00
|
|
|
"github.com/ethereum/go-ethereum/les/checkpointoracle"
|
2016-10-14 03:51:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/les/flowcontrol"
|
|
|
|
"github.com/ethereum/go-ethereum/light"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/enode"
|
2020-10-21 08:56:33 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/nodestate"
|
2016-10-14 03:51:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
bankKey, _ = crypto.GenerateKey()
|
|
|
|
bankAddr = crypto.PubkeyToAddress(bankKey.PublicKey)
|
|
|
|
bankFunds = big.NewInt(1000000000000000000)
|
2016-10-14 03:51:29 +00:00
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
userKey1, _ = crypto.GenerateKey()
|
|
|
|
userKey2, _ = crypto.GenerateKey()
|
|
|
|
userAddr1 = crypto.PubkeyToAddress(userKey1.PublicKey)
|
|
|
|
userAddr2 = crypto.PubkeyToAddress(userKey2.PublicKey)
|
2016-10-14 03:51:29 +00:00
|
|
|
|
|
|
|
testContractAddr common.Address
|
2019-08-21 09:29:34 +00:00
|
|
|
testContractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056")
|
2016-10-14 03:51:29 +00:00
|
|
|
testContractCodeDeployed = testContractCode[16:]
|
|
|
|
testContractDeployed = uint64(2)
|
|
|
|
|
2018-02-11 12:57:46 +00:00
|
|
|
testEventEmitterCode = common.Hex2Bytes("60606040523415600e57600080fd5b7f57050ab73f6b9ebdd9f76b8d4997793f48cf956e965ee070551b9ca0bb71584e60405160405180910390a160358060476000396000f3006060604052600080fd00a165627a7a723058203f727efcad8b5811f8cb1fc2620ce5e8c63570d697aef968172de296ea3994140029")
|
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
// Checkpoint registrar relative
|
|
|
|
registrarAddr common.Address
|
|
|
|
signerKey, _ = crypto.GenerateKey()
|
|
|
|
signerAddr = crypto.PubkeyToAddress(signerKey.PublicKey)
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// The block frequency for creating checkpoint(only used in test)
|
2019-11-06 21:09:37 +00:00
|
|
|
sectionSize = big.NewInt(128)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
|
|
|
|
// The number of confirmations needed to generate a checkpoint(only used in test).
|
2019-11-06 21:09:37 +00:00
|
|
|
processConfirms = big.NewInt(1)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
// The token bucket buffer limit for testing purpose.
|
|
|
|
testBufLimit = uint64(1000000)
|
|
|
|
|
|
|
|
// The buffer recharging speed for testing purpose.
|
2019-05-30 18:51:13 +00:00
|
|
|
testBufRecharge = uint64(1000)
|
2016-10-14 03:51:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
contract test {
|
|
|
|
|
|
|
|
uint256[100] data;
|
|
|
|
|
|
|
|
function Put(uint256 addr, uint256 value) {
|
|
|
|
data[addr] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Get(uint256 addr) constant returns (uint256 value) {
|
|
|
|
return data[addr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
// prepare pre-commits specified number customized blocks into chain.
|
|
|
|
func prepare(n int, backend *backends.SimulatedBackend) {
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
var (
|
|
|
|
ctx = context.Background()
|
|
|
|
signer = types.HomesteadSigner{}
|
|
|
|
)
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
switch i {
|
|
|
|
case 0:
|
|
|
|
// deploy checkpoint contract
|
2020-12-08 13:44:56 +00:00
|
|
|
auth, _ := bind.NewKeyedTransactorWithChainID(bankKey, big.NewInt(1337))
|
|
|
|
registrarAddr, _, _, _ = contract.DeployCheckpointOracle(auth, backend, []common.Address{signerAddr}, sectionSize, processConfirms, big.NewInt(1))
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
// bankUser transfers some ether to user1
|
|
|
|
nonce, _ := backend.PendingNonceAt(ctx, bankAddr)
|
|
|
|
tx, _ := types.SignTx(types.NewTransaction(nonce, userAddr1, big.NewInt(10000), params.TxGas, nil, nil), signer, bankKey)
|
|
|
|
backend.SendTransaction(ctx, tx)
|
|
|
|
case 1:
|
|
|
|
bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr)
|
|
|
|
userNonce1, _ := backend.PendingNonceAt(ctx, userAddr1)
|
|
|
|
|
|
|
|
// bankUser transfers more ether to user1
|
|
|
|
tx1, _ := types.SignTx(types.NewTransaction(bankNonce, userAddr1, big.NewInt(1000), params.TxGas, nil, nil), signer, bankKey)
|
|
|
|
backend.SendTransaction(ctx, tx1)
|
|
|
|
|
|
|
|
// user1 relays ether to user2
|
|
|
|
tx2, _ := types.SignTx(types.NewTransaction(userNonce1, userAddr2, big.NewInt(1000), params.TxGas, nil, nil), signer, userKey1)
|
|
|
|
backend.SendTransaction(ctx, tx2)
|
|
|
|
|
|
|
|
// user1 deploys a test contract
|
|
|
|
tx3, _ := types.SignTx(types.NewContractCreation(userNonce1+1, big.NewInt(0), 200000, big.NewInt(0), testContractCode), signer, userKey1)
|
|
|
|
backend.SendTransaction(ctx, tx3)
|
|
|
|
testContractAddr = crypto.CreateAddress(userAddr1, userNonce1+1)
|
|
|
|
|
|
|
|
// user1 deploys a event contract
|
|
|
|
tx4, _ := types.SignTx(types.NewContractCreation(userNonce1+2, big.NewInt(0), 200000, big.NewInt(0), testEventEmitterCode), signer, userKey1)
|
|
|
|
backend.SendTransaction(ctx, tx4)
|
|
|
|
case 2:
|
|
|
|
// bankUser transfer some ether to signer
|
|
|
|
bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr)
|
|
|
|
tx1, _ := types.SignTx(types.NewTransaction(bankNonce, signerAddr, big.NewInt(1000000000), params.TxGas, nil, nil), signer, bankKey)
|
|
|
|
backend.SendTransaction(ctx, tx1)
|
|
|
|
|
|
|
|
// invoke test contract
|
|
|
|
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001")
|
|
|
|
tx2, _ := types.SignTx(types.NewTransaction(bankNonce+1, testContractAddr, big.NewInt(0), 100000, nil, data), signer, bankKey)
|
|
|
|
backend.SendTransaction(ctx, tx2)
|
|
|
|
case 3:
|
|
|
|
// invoke test contract
|
|
|
|
bankNonce, _ := backend.PendingNonceAt(ctx, bankAddr)
|
|
|
|
data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002")
|
|
|
|
tx, _ := types.SignTx(types.NewTransaction(bankNonce, testContractAddr, big.NewInt(0), 100000, nil, data), signer, bankKey)
|
|
|
|
backend.SendTransaction(ctx, tx)
|
|
|
|
}
|
|
|
|
backend.Commit()
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-28 07:08:16 +00:00
|
|
|
// testIndexers creates a set of indexers with specified params for testing purpose.
|
2020-07-13 09:02:54 +00:00
|
|
|
func testIndexers(db ethdb.Database, odr light.OdrBackend, config *light.IndexerConfig, disablePruning bool) []*core.ChainIndexer {
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
var indexers [3]*core.ChainIndexer
|
2020-07-13 09:02:54 +00:00
|
|
|
indexers[0] = light.NewChtIndexer(db, odr, config.ChtSize, config.ChtConfirms, disablePruning)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
indexers[1] = eth.NewBloomIndexer(db, config.BloomSize, config.BloomConfirms)
|
2020-07-13 09:02:54 +00:00
|
|
|
indexers[2] = light.NewBloomTrieIndexer(db, odr, config.BloomSize, config.BloomTrieSize, disablePruning)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
// make bloomTrieIndexer as a child indexer of bloom indexer.
|
|
|
|
indexers[1].AddChildIndexer(indexers[2])
|
|
|
|
return indexers[:]
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
2020-02-26 09:41:24 +00:00
|
|
|
func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, indexers []*core.ChainIndexer, db ethdb.Database, peers *serverPeerSet, ulcServers []string, ulcFraction int) *clientHandler {
|
2016-10-14 03:51:29 +00:00
|
|
|
var (
|
2017-04-04 22:16:29 +00:00
|
|
|
evmux = new(event.TypeMux)
|
|
|
|
engine = ethash.NewFaker()
|
|
|
|
gspec = core.Genesis{
|
2019-08-21 09:29:34 +00:00
|
|
|
Config: params.AllEthashProtocolChanges,
|
|
|
|
Alloc: core.GenesisAlloc{bankAddr: {Balance: bankFunds}},
|
|
|
|
GasLimit: 100000000,
|
2017-03-02 13:03:33 +00:00
|
|
|
}
|
2020-01-07 09:24:21 +00:00
|
|
|
oracle *checkpointoracle.CheckpointOracle
|
2016-10-14 03:51:29 +00:00
|
|
|
)
|
2019-08-21 09:29:34 +00:00
|
|
|
genesis := gspec.MustCommit(db)
|
|
|
|
chain, _ := light.NewLightChain(odr, gspec.Config, engine, nil)
|
|
|
|
if indexers != nil {
|
|
|
|
checkpointConfig := ¶ms.CheckpointOracleConfig{
|
|
|
|
Address: crypto.CreateAddress(bankAddr, 0),
|
|
|
|
Signers: []common.Address{signerAddr},
|
|
|
|
Threshold: 1,
|
|
|
|
}
|
|
|
|
getLocal := func(index uint64) params.TrustedCheckpoint {
|
|
|
|
chtIndexer := indexers[0]
|
|
|
|
sectionHead := chtIndexer.SectionHead(index)
|
|
|
|
return params.TrustedCheckpoint{
|
|
|
|
SectionIndex: index,
|
|
|
|
SectionHead: sectionHead,
|
|
|
|
CHTRoot: light.GetChtRoot(db, index, sectionHead),
|
|
|
|
BloomRoot: light.GetBloomTrieRoot(db, index, sectionHead),
|
|
|
|
}
|
|
|
|
}
|
2020-01-07 09:24:21 +00:00
|
|
|
oracle = checkpointoracle.New(checkpointConfig, getLocal)
|
2017-06-21 10:27:38 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
client := &LightEthereum{
|
|
|
|
lesCommons: lesCommons{
|
|
|
|
genesis: genesis.Hash(),
|
|
|
|
config: ð.Config{LightPeers: 100, NetworkId: NetworkId},
|
|
|
|
chainConfig: params.AllEthashProtocolChanges,
|
|
|
|
iConfig: light.TestClientIndexerConfig,
|
|
|
|
chainDb: db,
|
|
|
|
oracle: oracle,
|
|
|
|
chainReader: chain,
|
|
|
|
closeCh: make(chan struct{}),
|
|
|
|
},
|
2020-02-26 09:41:24 +00:00
|
|
|
peers: peers,
|
2019-08-21 09:29:34 +00:00
|
|
|
reqDist: odr.retriever.dist,
|
|
|
|
retriever: odr.retriever,
|
|
|
|
odr: odr,
|
|
|
|
engine: engine,
|
|
|
|
blockchain: chain,
|
|
|
|
eventMux: evmux,
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
client.handler = newClientHandler(ulcServers, ulcFraction, nil, client)
|
2016-10-14 03:51:29 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
if client.oracle != nil {
|
2020-01-07 09:24:21 +00:00
|
|
|
client.oracle.Start(backend)
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
2020-07-28 15:02:35 +00:00
|
|
|
client.handler.start()
|
2019-08-21 09:29:34 +00:00
|
|
|
return client.handler
|
|
|
|
}
|
|
|
|
|
2020-10-21 08:56:33 +00:00
|
|
|
func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Database, clock mclock.Clock) (*serverHandler, *backends.SimulatedBackend) {
|
2019-08-21 09:29:34 +00:00
|
|
|
var (
|
|
|
|
gspec = core.Genesis{
|
|
|
|
Config: params.AllEthashProtocolChanges,
|
|
|
|
Alloc: core.GenesisAlloc{bankAddr: {Balance: bankFunds}},
|
|
|
|
GasLimit: 100000000,
|
|
|
|
}
|
2020-01-07 09:24:21 +00:00
|
|
|
oracle *checkpointoracle.CheckpointOracle
|
2019-08-21 09:29:34 +00:00
|
|
|
)
|
|
|
|
genesis := gspec.MustCommit(db)
|
|
|
|
|
|
|
|
// create a simulation backend and pre-commit several customized block to the database.
|
|
|
|
simulation := backends.NewSimulatedBackendWithDatabase(db, gspec.Alloc, 100000000)
|
|
|
|
prepare(blocks, simulation)
|
|
|
|
|
|
|
|
txpoolConfig := core.DefaultTxPoolConfig
|
|
|
|
txpoolConfig.Journal = ""
|
|
|
|
txpool := core.NewTxPool(txpoolConfig, gspec.Config, simulation.Blockchain())
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
if indexers != nil {
|
2019-08-21 09:29:34 +00:00
|
|
|
checkpointConfig := ¶ms.CheckpointOracleConfig{
|
|
|
|
Address: crypto.CreateAddress(bankAddr, 0),
|
|
|
|
Signers: []common.Address{signerAddr},
|
|
|
|
Threshold: 1,
|
|
|
|
}
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
getLocal := func(index uint64) params.TrustedCheckpoint {
|
|
|
|
chtIndexer := indexers[0]
|
|
|
|
sectionHead := chtIndexer.SectionHead(index)
|
|
|
|
return params.TrustedCheckpoint{
|
|
|
|
SectionIndex: index,
|
|
|
|
SectionHead: sectionHead,
|
|
|
|
CHTRoot: light.GetChtRoot(db, index, sectionHead),
|
|
|
|
BloomRoot: light.GetBloomTrieRoot(db, index, sectionHead),
|
|
|
|
}
|
|
|
|
}
|
2020-01-07 09:24:21 +00:00
|
|
|
oracle = checkpointoracle.New(checkpointConfig, getLocal)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
}
|
2020-10-21 08:56:33 +00:00
|
|
|
ns := nodestate.NewNodeStateMachine(nil, nil, mclock.System{}, serverSetup)
|
2019-08-21 09:29:34 +00:00
|
|
|
server := &LesServer{
|
|
|
|
lesCommons: lesCommons{
|
|
|
|
genesis: genesis.Hash(),
|
|
|
|
config: ð.Config{LightPeers: 100, NetworkId: NetworkId},
|
|
|
|
chainConfig: params.AllEthashProtocolChanges,
|
|
|
|
iConfig: light.TestServerIndexerConfig,
|
|
|
|
chainDb: db,
|
|
|
|
chainReader: simulation.Blockchain(),
|
|
|
|
oracle: oracle,
|
|
|
|
closeCh: make(chan struct{}),
|
|
|
|
},
|
2020-10-21 08:56:33 +00:00
|
|
|
ns: ns,
|
|
|
|
broadcaster: newBroadcaster(ns),
|
2019-08-21 09:29:34 +00:00
|
|
|
servingQueue: newServingQueue(int64(time.Millisecond*10), 1),
|
|
|
|
defParams: flowcontrol.ServerParams{
|
2016-10-14 03:51:29 +00:00
|
|
|
BufLimit: testBufLimit,
|
2019-05-30 18:51:13 +00:00
|
|
|
MinRecharge: testBufRecharge,
|
2019-08-21 09:29:34 +00:00
|
|
|
},
|
|
|
|
fcManager: flowcontrol.NewClientManager(nil, clock),
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
2020-09-14 20:44:20 +00:00
|
|
|
server.costTracker, server.minCapacity = newCostTracker(db, server.config)
|
2019-08-21 09:29:34 +00:00
|
|
|
server.costTracker.testCostList = testCostList(0) // Disable flow control mechanism.
|
2020-10-21 08:56:33 +00:00
|
|
|
server.clientPool = newClientPool(ns, db, testBufRecharge, defaultConnectedBias, clock, func(id enode.ID) {})
|
2019-08-27 11:07:25 +00:00
|
|
|
server.clientPool.setLimits(10000, 10000) // Assign enough capacity for clientpool
|
2019-08-21 09:29:34 +00:00
|
|
|
server.handler = newServerHandler(server, simulation.Blockchain(), db, txpool, func() bool { return true })
|
|
|
|
if server.oracle != nil {
|
2020-01-07 09:24:21 +00:00
|
|
|
server.oracle.Start(simulation)
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
server.servingQueue.setThreads(4)
|
2020-10-21 08:56:33 +00:00
|
|
|
ns.Start()
|
2019-08-21 09:29:34 +00:00
|
|
|
server.handler.start()
|
|
|
|
return server.handler, simulation
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// testPeer is a simulated peer to allow testing direct network calls.
|
|
|
|
type testPeer struct {
|
2020-02-26 09:41:24 +00:00
|
|
|
cpeer *clientPeer
|
|
|
|
speer *serverPeer
|
2019-08-21 09:29:34 +00:00
|
|
|
|
2016-10-14 03:51:29 +00:00
|
|
|
net p2p.MsgReadWriter // Network layer reader/writer to simulate remote messaging
|
|
|
|
app *p2p.MsgPipeRW // Application layer reader/writer to simulate the local side
|
|
|
|
}
|
|
|
|
|
|
|
|
// newTestPeer creates a new peer registered at the given protocol manager.
|
2019-08-21 09:29:34 +00:00
|
|
|
func newTestPeer(t *testing.T, name string, version int, handler *serverHandler, shake bool, testCost uint64) (*testPeer, <-chan error) {
|
2016-10-14 03:51:29 +00:00
|
|
|
// Create a message pipe to communicate through
|
|
|
|
app, net := p2p.MsgPipe()
|
|
|
|
|
|
|
|
// Generate a random id and create the peer
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
var id enode.ID
|
2016-10-14 03:51:29 +00:00
|
|
|
rand.Read(id[:])
|
2020-02-26 09:41:24 +00:00
|
|
|
peer := newClientPeer(version, NetworkId, p2p.NewPeer(id, name, nil), net)
|
2016-10-14 03:51:29 +00:00
|
|
|
|
|
|
|
// Start the peer on a new thread
|
2019-08-21 09:29:34 +00:00
|
|
|
errCh := make(chan error, 1)
|
2016-10-14 03:51:29 +00:00
|
|
|
go func() {
|
|
|
|
select {
|
2019-08-21 09:29:34 +00:00
|
|
|
case <-handler.closeCh:
|
|
|
|
errCh <- p2p.DiscQuitting
|
|
|
|
case errCh <- handler.handle(peer):
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
tp := &testPeer{
|
2020-02-26 09:41:24 +00:00
|
|
|
app: app,
|
|
|
|
net: net,
|
|
|
|
cpeer: peer,
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
// Execute any implicitly requested handshakes and return
|
|
|
|
if shake {
|
2019-08-21 09:29:34 +00:00
|
|
|
// Customize the cost table if required.
|
|
|
|
if testCost != 0 {
|
|
|
|
handler.server.costTracker.testCostList = testCostList(testCost)
|
|
|
|
}
|
2018-01-30 16:39:32 +00:00
|
|
|
var (
|
2019-08-21 09:29:34 +00:00
|
|
|
genesis = handler.blockchain.Genesis()
|
|
|
|
head = handler.blockchain.CurrentHeader()
|
|
|
|
td = handler.blockchain.GetTd(head.Hash(), head.Number.Uint64())
|
2018-01-30 16:39:32 +00:00
|
|
|
)
|
2019-08-21 09:29:34 +00:00
|
|
|
tp.handshake(t, td, head.Hash(), head.Number.Uint64(), genesis.Hash(), testCostList(testCost))
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
return tp, errCh
|
|
|
|
}
|
|
|
|
|
|
|
|
// close terminates the local side of the peer, notifying the remote protocol
|
|
|
|
// manager of termination.
|
|
|
|
func (p *testPeer) close() {
|
|
|
|
p.app.Close()
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 10:25:52 +00:00
|
|
|
func newTestPeerPair(name string, version int, server *serverHandler, client *clientHandler) (*testPeer, *testPeer, error) {
|
2016-10-14 03:51:29 +00:00
|
|
|
// Create a message pipe to communicate through
|
|
|
|
app, net := p2p.MsgPipe()
|
|
|
|
|
|
|
|
// Generate a random id and create the peer
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
var id enode.ID
|
2016-10-14 03:51:29 +00:00
|
|
|
rand.Read(id[:])
|
|
|
|
|
2020-02-26 09:41:24 +00:00
|
|
|
peer1 := newClientPeer(version, NetworkId, p2p.NewPeer(id, name, nil), net)
|
|
|
|
peer2 := newServerPeer(version, NetworkId, false, p2p.NewPeer(id, name, nil), app)
|
2016-10-14 03:51:29 +00:00
|
|
|
|
|
|
|
// Start the peer on a new thread
|
2019-08-21 09:29:34 +00:00
|
|
|
errc1 := make(chan error, 1)
|
2016-10-14 03:51:29 +00:00
|
|
|
errc2 := make(chan error, 1)
|
|
|
|
go func() {
|
|
|
|
select {
|
2019-08-21 09:29:34 +00:00
|
|
|
case <-server.closeCh:
|
|
|
|
errc1 <- p2p.DiscQuitting
|
|
|
|
case errc1 <- server.handle(peer1):
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
go func() {
|
|
|
|
select {
|
2019-08-21 09:29:34 +00:00
|
|
|
case <-client.closeCh:
|
2020-03-12 10:25:52 +00:00
|
|
|
errc2 <- p2p.DiscQuitting
|
|
|
|
case errc2 <- client.handle(peer2):
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
}()
|
2020-03-12 10:25:52 +00:00
|
|
|
// Ensure the connection is established or exits when any error occurs
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case err := <-errc1:
|
|
|
|
return nil, nil, fmt.Errorf("Failed to establish protocol connection %v", err)
|
|
|
|
case err := <-errc2:
|
|
|
|
return nil, nil, fmt.Errorf("Failed to establish protocol connection %v", err)
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
if atomic.LoadUint32(&peer1.serving) == 1 && atomic.LoadUint32(&peer2.serving) == 1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(50 * time.Millisecond)
|
|
|
|
}
|
|
|
|
return &testPeer{cpeer: peer1, net: net, app: app}, &testPeer{speer: peer2, net: app, app: net}, nil
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// handshake simulates a trivial handshake that expects the same state from the
|
|
|
|
// remote side as we are simulating locally.
|
2019-08-21 09:29:34 +00:00
|
|
|
func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, headNum uint64, genesis common.Hash, costList RequestCostList) {
|
2016-10-14 03:51:29 +00:00
|
|
|
var expList keyValueList
|
2020-02-26 09:41:24 +00:00
|
|
|
expList = expList.add("protocolVersion", uint64(p.cpeer.version))
|
2016-10-14 03:51:29 +00:00
|
|
|
expList = expList.add("networkId", uint64(NetworkId))
|
|
|
|
expList = expList.add("headTd", td)
|
|
|
|
expList = expList.add("headHash", head)
|
|
|
|
expList = expList.add("headNum", headNum)
|
|
|
|
expList = expList.add("genesisHash", genesis)
|
|
|
|
sendList := make(keyValueList, len(expList))
|
|
|
|
copy(sendList, expList)
|
|
|
|
expList = expList.add("serveHeaders", nil)
|
|
|
|
expList = expList.add("serveChainSince", uint64(0))
|
|
|
|
expList = expList.add("serveStateSince", uint64(0))
|
2019-05-30 18:51:13 +00:00
|
|
|
expList = expList.add("serveRecentState", uint64(core.TriesInMemory-4))
|
2016-10-14 03:51:29 +00:00
|
|
|
expList = expList.add("txRelay", nil)
|
|
|
|
expList = expList.add("flowControl/BL", testBufLimit)
|
2019-05-30 18:51:13 +00:00
|
|
|
expList = expList.add("flowControl/MRR", testBufRecharge)
|
2019-08-21 09:29:34 +00:00
|
|
|
expList = expList.add("flowControl/MRC", costList)
|
2016-10-14 03:51:29 +00:00
|
|
|
|
|
|
|
if err := p2p.ExpectMsg(p.app, StatusMsg, expList); err != nil {
|
|
|
|
t.Fatalf("status recv: %v", err)
|
|
|
|
}
|
|
|
|
if err := p2p.Send(p.app, StatusMsg, sendList); err != nil {
|
|
|
|
t.Fatalf("status send: %v", err)
|
|
|
|
}
|
2020-02-26 09:41:24 +00:00
|
|
|
p.cpeer.fcParams = flowcontrol.ServerParams{
|
2016-10-14 03:51:29 +00:00
|
|
|
BufLimit: testBufLimit,
|
2019-05-30 18:51:13 +00:00
|
|
|
MinRecharge: testBufRecharge,
|
2016-10-14 03:51:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
type indexerCallback func(*core.ChainIndexer, *core.ChainIndexer, *core.ChainIndexer)
|
2018-08-28 07:08:16 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
// testClient represents a client for testing with necessary auxiliary fields.
|
|
|
|
type testClient struct {
|
|
|
|
clock mclock.Clock
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
db ethdb.Database
|
2019-08-21 09:29:34 +00:00
|
|
|
peer *testPeer
|
|
|
|
handler *clientHandler
|
|
|
|
|
|
|
|
chtIndexer *core.ChainIndexer
|
|
|
|
bloomIndexer *core.ChainIndexer
|
|
|
|
bloomTrieIndexer *core.ChainIndexer
|
|
|
|
}
|
|
|
|
|
|
|
|
// testServer represents a server for testing with necessary auxiliary fields.
|
|
|
|
type testServer struct {
|
|
|
|
clock mclock.Clock
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
backend *backends.SimulatedBackend
|
2019-08-21 09:29:34 +00:00
|
|
|
db ethdb.Database
|
|
|
|
peer *testPeer
|
|
|
|
handler *serverHandler
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
|
2018-08-28 07:08:16 +00:00
|
|
|
chtIndexer *core.ChainIndexer
|
|
|
|
bloomIndexer *core.ChainIndexer
|
|
|
|
bloomTrieIndexer *core.ChainIndexer
|
|
|
|
}
|
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
func newServerEnv(t *testing.T, blocks int, protocol int, callback indexerCallback, simClock bool, newPeer bool, testCost uint64) (*testServer, func()) {
|
2018-09-24 12:57:49 +00:00
|
|
|
db := rawdb.NewMemoryDatabase()
|
2020-07-13 09:02:54 +00:00
|
|
|
indexers := testIndexers(db, nil, light.TestServerIndexerConfig, true)
|
2018-08-28 07:08:16 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
var clock mclock.Clock = &mclock.System{}
|
|
|
|
if simClock {
|
|
|
|
clock = &mclock.Simulated{}
|
|
|
|
}
|
2020-10-21 08:56:33 +00:00
|
|
|
handler, b := newTestServerHandler(blocks, indexers, db, clock)
|
2019-08-21 09:29:34 +00:00
|
|
|
|
|
|
|
var peer *testPeer
|
|
|
|
if newPeer {
|
|
|
|
peer, _ = newTestPeer(t, "peer", protocol, handler, true, testCost)
|
|
|
|
}
|
2018-08-28 07:08:16 +00:00
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
cIndexer, bIndexer, btIndexer := indexers[0], indexers[1], indexers[2]
|
2019-08-21 09:29:34 +00:00
|
|
|
cIndexer.Start(handler.blockchain)
|
|
|
|
bIndexer.Start(handler.blockchain)
|
2018-08-28 07:08:16 +00:00
|
|
|
|
|
|
|
// Wait until indexers generate enough index data.
|
2019-08-21 09:29:34 +00:00
|
|
|
if callback != nil {
|
|
|
|
callback(cIndexer, bIndexer, btIndexer)
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
server := &testServer{
|
|
|
|
clock: clock,
|
|
|
|
backend: b,
|
|
|
|
db: db,
|
|
|
|
peer: peer,
|
|
|
|
handler: handler,
|
|
|
|
chtIndexer: cIndexer,
|
|
|
|
bloomIndexer: bIndexer,
|
|
|
|
bloomTrieIndexer: btIndexer,
|
|
|
|
}
|
|
|
|
teardown := func() {
|
|
|
|
if newPeer {
|
2018-08-28 07:08:16 +00:00
|
|
|
peer.close()
|
2020-02-26 09:41:24 +00:00
|
|
|
peer.cpeer.close()
|
2019-07-31 08:35:57 +00:00
|
|
|
b.Close()
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
cIndexer.Close()
|
|
|
|
bIndexer.Close()
|
|
|
|
}
|
|
|
|
return server, teardown
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
|
|
|
|
2020-07-13 09:02:54 +00:00
|
|
|
func newClientServerEnv(t *testing.T, blocks int, protocol int, callback indexerCallback, ulcServers []string, ulcFraction int, simClock bool, connect bool, disablePruning bool) (*testServer, *testClient, func()) {
|
2019-08-21 09:29:34 +00:00
|
|
|
sdb, cdb := rawdb.NewMemoryDatabase(), rawdb.NewMemoryDatabase()
|
2020-10-21 08:56:33 +00:00
|
|
|
speers := newServerPeerSet()
|
2018-08-28 07:08:16 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
var clock mclock.Clock = &mclock.System{}
|
|
|
|
if simClock {
|
|
|
|
clock = &mclock.Simulated{}
|
|
|
|
}
|
2020-02-26 09:41:24 +00:00
|
|
|
dist := newRequestDistributor(speers, clock)
|
2020-05-22 11:46:34 +00:00
|
|
|
rm := newRetrieveManager(speers, dist, func() time.Duration { return time.Millisecond * 500 })
|
2019-08-21 09:29:34 +00:00
|
|
|
odr := NewLesOdr(cdb, light.TestClientIndexerConfig, rm)
|
2018-08-28 07:08:16 +00:00
|
|
|
|
2020-07-13 09:02:54 +00:00
|
|
|
sindexers := testIndexers(sdb, nil, light.TestServerIndexerConfig, true)
|
|
|
|
cIndexers := testIndexers(cdb, odr, light.TestClientIndexerConfig, disablePruning)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
scIndexer, sbIndexer, sbtIndexer := sindexers[0], sindexers[1], sindexers[2]
|
|
|
|
ccIndexer, cbIndexer, cbtIndexer := cIndexers[0], cIndexers[1], cIndexers[2]
|
|
|
|
odr.SetIndexers(ccIndexer, cbIndexer, cbtIndexer)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
|
2020-10-21 08:56:33 +00:00
|
|
|
server, b := newTestServerHandler(blocks, sindexers, sdb, clock)
|
2020-02-26 09:41:24 +00:00
|
|
|
client := newTestClientHandler(b, odr, cIndexers, cdb, speers, ulcServers, ulcFraction)
|
2018-08-28 07:08:16 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
scIndexer.Start(server.blockchain)
|
|
|
|
sbIndexer.Start(server.blockchain)
|
|
|
|
ccIndexer.Start(client.backend.blockchain)
|
|
|
|
cbIndexer.Start(client.backend.blockchain)
|
2018-08-28 07:08:16 +00:00
|
|
|
|
2019-08-21 09:29:34 +00:00
|
|
|
if callback != nil {
|
|
|
|
callback(scIndexer, sbIndexer, sbtIndexer)
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
|
|
|
var (
|
2020-03-12 10:25:52 +00:00
|
|
|
err error
|
2019-08-21 09:29:34 +00:00
|
|
|
speer, cpeer *testPeer
|
2018-08-28 07:08:16 +00:00
|
|
|
)
|
2019-08-21 09:29:34 +00:00
|
|
|
if connect {
|
2020-03-12 10:25:52 +00:00
|
|
|
done := make(chan struct{})
|
2021-01-19 09:52:45 +00:00
|
|
|
client.syncEnd = func(_ *types.Header) { close(done) }
|
2020-03-12 10:25:52 +00:00
|
|
|
cpeer, speer, err = newTestPeerPair("peer", protocol, server, client)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to connect testing peers %v", err)
|
|
|
|
}
|
2018-08-28 07:08:16 +00:00
|
|
|
select {
|
2020-03-12 10:25:52 +00:00
|
|
|
case <-done:
|
2020-07-13 09:02:54 +00:00
|
|
|
case <-time.After(10 * time.Second):
|
2020-03-12 10:25:52 +00:00
|
|
|
t.Fatal("test peer did not connect and sync within 3s")
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
s := &testServer{
|
|
|
|
clock: clock,
|
|
|
|
backend: b,
|
|
|
|
db: sdb,
|
|
|
|
peer: cpeer,
|
|
|
|
handler: server,
|
|
|
|
chtIndexer: scIndexer,
|
|
|
|
bloomIndexer: sbIndexer,
|
|
|
|
bloomTrieIndexer: sbtIndexer,
|
|
|
|
}
|
|
|
|
c := &testClient{
|
|
|
|
clock: clock,
|
|
|
|
db: cdb,
|
|
|
|
peer: speer,
|
|
|
|
handler: client,
|
|
|
|
chtIndexer: ccIndexer,
|
|
|
|
bloomIndexer: cbIndexer,
|
|
|
|
bloomTrieIndexer: cbtIndexer,
|
|
|
|
}
|
|
|
|
teardown := func() {
|
|
|
|
if connect {
|
|
|
|
speer.close()
|
|
|
|
cpeer.close()
|
2020-02-26 09:41:24 +00:00
|
|
|
cpeer.cpeer.close()
|
|
|
|
speer.speer.close()
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|
2019-08-21 09:29:34 +00:00
|
|
|
ccIndexer.Close()
|
|
|
|
cbIndexer.Close()
|
|
|
|
scIndexer.Close()
|
|
|
|
sbIndexer.Close()
|
|
|
|
b.Close()
|
|
|
|
}
|
|
|
|
return s, c, teardown
|
2018-08-28 07:08:16 +00:00
|
|
|
}
|