Add account blockchain to node

pull/83/head^2
Rongjian Lan 6 years ago
parent 7261b06981
commit fbdccaffe1
  1. 22
      node/node.go
  2. BIN
      transactions.rlp

@ -5,15 +5,16 @@ import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/core/vm"
"net" "net"
"sync" "sync"
"time" "time"
"github.com/harmony-one/harmony/blockchain" "github.com/harmony-one/harmony/blockchain"
"github.com/harmony-one/harmony/client" "github.com/harmony-one/harmony/client"
"github.com/harmony-one/harmony/consensus" bft "github.com/harmony-one/harmony/consensus"
"github.com/harmony-one/harmony/crypto/pki" "github.com/harmony-one/harmony/crypto/pki"
"github.com/harmony-one/harmony/db" hdb "github.com/harmony-one/harmony/db"
"github.com/harmony-one/harmony/log" "github.com/harmony-one/harmony/log"
"github.com/harmony-one/harmony/p2p" "github.com/harmony-one/harmony/p2p"
proto_identity "github.com/harmony-one/harmony/proto/identity" proto_identity "github.com/harmony-one/harmony/proto/identity"
@ -27,12 +28,12 @@ type NetworkNode struct {
// Node represents a program (machine) participating in the network // Node represents a program (machine) participating in the network
// TODO(minhdoan, rj): consider using BlockChannel *chan blockchain.Block for efficiency. // TODO(minhdoan, rj): consider using BlockChannel *chan blockchain.Block for efficiency.
type Node struct { type Node struct {
Consensus *consensus.Consensus // Consensus object containing all Consensus related data (e.g. committee members, signatures, commits) Consensus *bft.Consensus // Consensus object containing all Consensus related data (e.g. committee members, signatures, commits)
BlockChannel chan blockchain.Block // The channel to receive new blocks from Node BlockChannel chan blockchain.Block // The channel to receive new blocks from Node
pendingTransactions []*blockchain.Transaction // All the transactions received but not yet processed for Consensus pendingTransactions []*blockchain.Transaction // All the transactions received but not yet processed for Consensus
transactionInConsensus []*blockchain.Transaction // The transactions selected into the new block and under Consensus process transactionInConsensus []*blockchain.Transaction // The transactions selected into the new block and under Consensus process
blockchain *blockchain.Blockchain // The blockchain for the shard where this node belongs blockchain *blockchain.Blockchain // The blockchain for the shard where this node belongs
db *db.LDBDatabase // LevelDB to store blockchain. db *hdb.LDBDatabase // LevelDB to store blockchain.
UtxoPool *blockchain.UTXOPool // The corresponding UTXO pool of the current blockchain UtxoPool *blockchain.UTXOPool // The corresponding UTXO pool of the current blockchain
CrossTxsInConsensus []*blockchain.CrossShardTxAndProof // The cross shard txs that is under consensus, the proof is not filled yet. CrossTxsInConsensus []*blockchain.CrossShardTxAndProof // The cross shard txs that is under consensus, the proof is not filled yet.
CrossTxsToReturn []*blockchain.CrossShardTxAndProof // The cross shard txs and proof that needs to be sent back to the user client. CrossTxsToReturn []*blockchain.CrossShardTxAndProof // The cross shard txs and proof that needs to be sent back to the user client.
@ -171,7 +172,7 @@ func DeserializeNode(d []byte) *NetworkNode {
} }
// New creates a new node. // New creates a new node.
func New(consensus *consensus.Consensus, db *db.LDBDatabase) *Node { func New(consensus *bft.Consensus, db *hdb.LDBDatabase) *Node {
node := Node{} node := Node{}
if consensus != nil { if consensus != nil {
@ -189,9 +190,14 @@ func New(consensus *consensus.Consensus, db *db.LDBDatabase) *Node {
node.blockchain = genesisBlock node.blockchain = genesisBlock
// Genesis Block (account model) // Genesis Block (account model)
//gspec = core.Genesis{} database := hdb.NewMemDatabase()
// gspec := core.Genesis{}
//genesis := gspec.MustCommit(ethdb.NewMemDatabase())
genesis := gspec.MustCommit(database)
fmt.Println(genesis.Root())
chain, _ := core.NewBlockChain(database, nil, gspec.Config, bft.NewFaker(), vm.Config{}, nil)
node.chain = chain
// UTXO pool from Genesis block // UTXO pool from Genesis block
node.UtxoPool = blockchain.CreateUTXOPoolFromGenesisBlock(node.blockchain.Blocks[0]) node.UtxoPool = blockchain.CreateUTXOPoolFromGenesisBlock(node.blockchain.Blocks[0])

Binary file not shown.
Loading…
Cancel
Save