chainntnfs/test_util: set 10ms trickleInterval for miner

This commit is contained in:
Johan T. Halseth 2018-08-24 13:50:47 +02:00
parent ecc91305ac
commit cb3ec07685
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -26,6 +26,13 @@ import (
"github.com/lightninglabs/neutrino" "github.com/lightninglabs/neutrino"
) )
var (
// trickleInterval is the interval at which the miner should trickle
// transactions to its peers. We'll set it small to ensure the miner
// propagates transactions quickly in the tests.
trickleInterval = 10 * time.Millisecond
)
var ( var (
NetParams = &chaincfg.RegressionNetParams NetParams = &chaincfg.RegressionNetParams
@ -62,6 +69,7 @@ func GetTestTxidAndScript(h *rpctest.Harness) (*chainhash.Hash, []byte, error) {
// WaitForMempoolTx waits for the txid to be seen in the miner's mempool. // WaitForMempoolTx waits for the txid to be seen in the miner's mempool.
func WaitForMempoolTx(miner *rpctest.Harness, txid *chainhash.Hash) error { func WaitForMempoolTx(miner *rpctest.Harness, txid *chainhash.Hash) error {
timeout := time.After(10 * time.Second) timeout := time.After(10 * time.Second)
trickle := time.After(2 * trickleInterval)
for { for {
// Check for the harness' knowledge of the txid. // Check for the harness' knowledge of the txid.
tx, err := miner.Node.GetRawTransaction(txid) tx, err := miner.Node.GetRawTransaction(txid)
@ -84,6 +92,16 @@ func WaitForMempoolTx(miner *rpctest.Harness, txid *chainhash.Hash) error {
} }
} }
// To ensure any transactions propagate from the miner to the peers
// before returning, ensure we have waited for at least
// 2*trickleInterval before returning.
select {
case <-trickle:
case <-timeout:
return errors.New("timeout waiting for trickle interval. " +
"Trickle interval to large?")
}
return nil return nil
} }
@ -141,6 +159,10 @@ func NewMiner(t *testing.T, extraArgs []string, createChain bool,
t.Helper() t.Helper()
// Add the trickle interval argument to the extra args.
trickle := fmt.Sprintf("--trickleinterval=%v", trickleInterval)
extraArgs = append(extraArgs, trickle)
node, err := rpctest.New(NetParams, nil, extraArgs) node, err := rpctest.New(NetParams, nil, extraArgs)
if err != nil { if err != nil {
t.Fatalf("unable to create backend node: %v", err) t.Fatalf("unable to create backend node: %v", err)