Merge branch 'master' of github.com:simple-rules/harmony-benchmark

pull/61/head
ak 6 years ago
commit 679831880a
  1. 2
      blockchain/blockchain.go
  2. 2
      client/btctxgen/main.go
  3. 7
      client/txgen/main.go
  4. 16
      db/db_test.go

@ -3,6 +3,7 @@ package blockchain
import (
"bytes"
"encoding/hex"
"github.com/dedis/kyber"
"github.com/simple-rules/harmony-benchmark/crypto/pki"
)
@ -183,6 +184,7 @@ func (bc *Blockchain) VerifyNewBlockAndUpdate(utxopool *UTXOPool, block *Block)
}
// CreateBlockchain creates a new blockchain DB
// TODO(minhdoan): This func is not used, consider to remove.
func CreateBlockchain(address [20]byte, shardId uint32) *Blockchain {
// TODO: We assume we have not created any blockchain before.
// In current bitcoin, we can check if we created a blockchain before accessing local db.

@ -114,7 +114,7 @@ LOOP:
if btcTXOAddr == nil {
log.Warn("TxOut: can't decode address")
}
txo := blockchain.TXOutput{int(btcTXO.Value), btcTXOAddr.Hash160, nodeShardID}
txo := blockchain.TXOutput{Amount: int(btcTXO.Value), Address: btcTXOAddr.Hash160, ShardID: nodeShardID}
tx.TxOutput = append(tx.TxOutput, txo)
}
tx.SetID()

@ -164,12 +164,13 @@ func generateCrossShardTx(txInfo *TxInfo) {
}
// Spend the utxo from the current shard to a random address in [0 - N)
txout := blockchain.TXOutput{txInfo.value, pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), nodeShardID}
txout := blockchain.TXOutput{Amount: txInfo.value, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: nodeShardID}
txOutputs := []blockchain.TXOutput{txout}
// Spend the utxo from the other shard, if any, to a random address in [0 - N)
if crossTxin != nil {
crossTxout := blockchain.TXOutput{crossUtxoValue, pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), uint32(crossShardId)}
crossTxout := blockchain.TXOutput{Amount: crossUtxoValue, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: uint32(crossShardId)}
txOutputs = append(txOutputs, crossTxout)
}
@ -202,7 +203,7 @@ func generateSingleShardTx(txInfo *TxInfo) {
txin := blockchain.NewTXInput(blockchain.NewOutPoint(&txInfo.id, txInfo.index), txInfo.address, nodeShardID)
// Spend the utxo to a random address in [0 - N)
txout := blockchain.TXOutput{txInfo.value, pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), nodeShardID}
txout := blockchain.TXOutput{Amount: txInfo.value, Address: pki.GetAddressFromInt(rand.Intn(setting.numOfAddress) + 1), ShardID: nodeShardID}
tx := blockchain.Transaction{ID: [32]byte{}, TxInput: []blockchain.TXInput{*txin}, TxOutput: []blockchain.TXOutput{txout}, Proofs: nil}
priKeyInt, ok := client.LookUpIntPriKey(txInfo.address)

@ -1,4 +1,4 @@
package db_test
package db
import (
"bytes"
@ -8,16 +8,14 @@ import (
"strconv"
"sync"
"testing"
"github.com/simple-rules/harmony-benchmark/db"
)
func newTestLDB() (*db.LDBDatabase, func()) {
func newTestLDB() (*LDBDatabase, func()) {
dirname, err := ioutil.TempDir(os.TempDir(), "db_test_")
if err != nil {
panic("failed to create test file: " + err.Error())
}
db, err := db.NewLDBDatabase(dirname, 0, 0)
db, err := NewLDBDatabase(dirname, 0, 0)
if err != nil {
panic("failed to create test database: " + err.Error())
}
@ -37,10 +35,10 @@ func TestLDB_PutGet(t *testing.T) {
}
func TestMemoryDB_PutGet(t *testing.T) {
testPutGet(db.NewMemDatabase(), t)
testPutGet(NewMemDatabase(), t)
}
func testPutGet(db db.Database, t *testing.T) {
func testPutGet(db Database, t *testing.T) {
t.Parallel()
for _, k := range test_values {
@ -136,10 +134,10 @@ func TestLDB_ParallelPutGet(t *testing.T) {
}
func TestMemoryDB_ParallelPutGet(t *testing.T) {
testParallelPutGet(db.NewMemDatabase(), t)
testParallelPutGet(NewMemDatabase(), t)
}
func testParallelPutGet(db db.Database, t *testing.T) {
func testParallelPutGet(db Database, t *testing.T) {
const n = 8
var pending sync.WaitGroup

Loading…
Cancel
Save