mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 23:02:16 +00:00
some public convenience functions, extra debug errors on ExecTx
This commit is contained in:
parent
55d8e29e32
commit
deff645dba
@ -25,6 +25,12 @@ func App() *confer.Config {
|
|||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetApp(a *confer.Config) {
|
||||||
|
appMtx.Lock()
|
||||||
|
defer appMtx.Unlock()
|
||||||
|
app = a
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: If you change this, maybe also change initDefaults()
|
// NOTE: If you change this, maybe also change initDefaults()
|
||||||
var defaultConfig = `# This is a TOML config file.
|
var defaultConfig = `# This is a TOML config file.
|
||||||
# For more information, see https://github.com/toml-lang/toml
|
# For more information, see https://github.com/toml-lang/toml
|
||||||
@ -57,7 +63,7 @@ ListenAddr = "127.0.0.1:8081"
|
|||||||
# TODO: Document options
|
# TODO: Document options
|
||||||
`
|
`
|
||||||
|
|
||||||
var defaultGenesis = `
|
var DefaultGenesis = `
|
||||||
{
|
{
|
||||||
"Accounts": [
|
"Accounts": [
|
||||||
{
|
{
|
||||||
@ -114,7 +120,7 @@ func Init(rootDir string) {
|
|||||||
|
|
||||||
// Write default config file if missing.
|
// Write default config file if missing.
|
||||||
checkWriteFile(configFile, defaultConfig)
|
checkWriteFile(configFile, defaultConfig)
|
||||||
checkWriteFile(genesisFile, defaultGenesis)
|
checkWriteFile(genesisFile, DefaultGenesis)
|
||||||
|
|
||||||
// Initialize Config
|
// Initialize Config
|
||||||
app = confer.NewConfig()
|
app = confer.NewConfig()
|
||||||
|
@ -123,6 +123,35 @@ func (n *Node) inboundConnectionRoutine(l p2p.Listener) {
|
|||||||
// cleanup
|
// cleanup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *Node) DialSeed() {
|
||||||
|
addr := p2p.NewNetAddressString(config.App().GetString("SeedNode"))
|
||||||
|
peer, err := n.sw.DialPeerWithAddress(addr)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error dialing seed", "error", err)
|
||||||
|
//n.book.MarkAttempt(addr)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
log.Info("Connected to seed", "peer", peer)
|
||||||
|
n.book.AddAddress(addr, addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) StartRpc() {
|
||||||
|
rpc.SetRPCBlockStore(n.blockStore)
|
||||||
|
rpc.SetRPCConsensusState(n.consensusState)
|
||||||
|
rpc.SetRPCMempoolReactor(n.mempoolReactor)
|
||||||
|
rpc.SetRPCSwitch(n.sw)
|
||||||
|
rpc.StartHTTPServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) ConsensusState() *consensus.ConsensusState {
|
||||||
|
return n.consensusState
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Node) MempoolReactor() *mempl.MempoolReactor {
|
||||||
|
return n.mempoolReactor
|
||||||
|
}
|
||||||
|
|
||||||
func Daemon() {
|
func Daemon() {
|
||||||
|
|
||||||
// Create & start node
|
// Create & start node
|
||||||
@ -133,25 +162,12 @@ func Daemon() {
|
|||||||
|
|
||||||
// If seedNode is provided by config, dial out.
|
// If seedNode is provided by config, dial out.
|
||||||
if config.App().GetString("SeedNode") != "" {
|
if config.App().GetString("SeedNode") != "" {
|
||||||
addr := p2p.NewNetAddressString(config.App().GetString("SeedNode"))
|
n.DialSeed()
|
||||||
peer, err := n.sw.DialPeerWithAddress(addr)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Error dialing seed", "error", err)
|
|
||||||
//n.book.MarkAttempt(addr)
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
log.Info("Connected to seed", "peer", peer)
|
|
||||||
n.book.AddAddress(addr, addr)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the RPC server.
|
// Run the RPC server.
|
||||||
if config.App().GetString("RPC.HTTP.ListenAddr") != "" {
|
if config.App().GetString("RPC.HTTP.ListenAddr") != "" {
|
||||||
rpc.SetRPCBlockStore(n.blockStore)
|
n.StartRpc()
|
||||||
rpc.SetRPCConsensusState(n.consensusState)
|
|
||||||
rpc.SetRPCMempoolReactor(n.mempoolReactor)
|
|
||||||
rpc.SetRPCSwitch(n.sw)
|
|
||||||
rpc.StartHTTPServer()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep forever and then...
|
// Sleep forever and then...
|
||||||
|
@ -20,6 +20,10 @@ func getLevel(lvlString string) log15.Lvl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
InitLog()
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitLog() {
|
||||||
handlers := []log15.Handler{}
|
handlers := []log15.Handler{}
|
||||||
|
|
||||||
// By default, there's a stdout terminal format handler.
|
// By default, there's a stdout terminal format handler.
|
||||||
|
@ -282,18 +282,22 @@ func (s *State) ExecTx(tx_ blk.Tx, runCall bool) error {
|
|||||||
// Validate input
|
// Validate input
|
||||||
inAcc = s.GetAccount(tx.Input.Address)
|
inAcc = s.GetAccount(tx.Input.Address)
|
||||||
if inAcc == nil {
|
if inAcc == nil {
|
||||||
|
log.Debug("Can't find in account %X", tx.Input.Address)
|
||||||
return blk.ErrTxInvalidAddress
|
return blk.ErrTxInvalidAddress
|
||||||
}
|
}
|
||||||
// pubKey should be present in either "inAcc" or "tx.Input"
|
// pubKey should be present in either "inAcc" or "tx.Input"
|
||||||
if err := checkInputPubKey(inAcc, tx.Input); err != nil {
|
if err := checkInputPubKey(inAcc, tx.Input); err != nil {
|
||||||
|
log.Debug("Can't find pubkey for %X", tx.Input.Address)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
signBytes := account.SignBytes(tx)
|
signBytes := account.SignBytes(tx)
|
||||||
err := s.ValidateInput(inAcc, signBytes, tx.Input)
|
err := s.ValidateInput(inAcc, signBytes, tx.Input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug("ValidateInput failed on %X:", tx.Input.Address)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if tx.Input.Amount < tx.Fee {
|
if tx.Input.Amount < tx.Fee {
|
||||||
|
log.Debug("Sender did not send enough to cover the fee %X", tx.Input.Address)
|
||||||
return blk.ErrTxInsufficientFunds
|
return blk.ErrTxInsufficientFunds
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,10 +305,12 @@ func (s *State) ExecTx(tx_ blk.Tx, runCall bool) error {
|
|||||||
if !createAccount {
|
if !createAccount {
|
||||||
// Validate output
|
// Validate output
|
||||||
if len(tx.Address) != 20 {
|
if len(tx.Address) != 20 {
|
||||||
|
log.Debug("Destination address is not 20 bytes %X", tx.Address)
|
||||||
return blk.ErrTxInvalidAddress
|
return blk.ErrTxInvalidAddress
|
||||||
}
|
}
|
||||||
outAcc = s.GetAccount(tx.Address)
|
outAcc = s.GetAccount(tx.Address)
|
||||||
if outAcc == nil {
|
if outAcc == nil {
|
||||||
|
log.Debug("Cannot find destination address %X", tx.Address)
|
||||||
return blk.ErrTxInvalidAddress
|
return blk.ErrTxInvalidAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,6 +342,7 @@ func (s *State) ExecTx(tx_ blk.Tx, runCall bool) error {
|
|||||||
} else {
|
} else {
|
||||||
callee, err = appState.CreateAccount(caller)
|
callee, err = appState.CreateAccount(caller)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug("Error creating account")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"code.google.com/p/go.crypto/ripemd160"
|
"code.google.com/p/go.crypto/ripemd160"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"github.com/tendermint/tendermint/vm/secp256k1"
|
"github.com/tendermint/tendermint/vm/secp256k1"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/vm/sha3"
|
"github.com/tendermint/tendermint/vm/sha3"
|
||||||
|
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user