Merge branch 'master' of github.com:tomochain/tomochain

This commit is contained in:
Nguyen Sy Thanh Son 2018-12-24 10:58:27 +00:00
commit 10d04fff11
14 changed files with 36 additions and 19 deletions

View file

@ -28,6 +28,7 @@ import (
"unicode" "unicode"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/dashboard" "github.com/ethereum/go-ethereum/dashboard"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/internal/debug"
@ -151,6 +152,11 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
ctx.Set(utils.NATFlag.Name, cfg.NAT) ctx.Set(utils.NATFlag.Name, cfg.NAT)
} }
// Check testnet is enable.
if ctx.GlobalBool(utils.TomoTestnetFlag.Name) {
common.IsTestnet = true
}
// read passwords from environment // read passwords from environment
passwords := []string{} passwords := []string{}
for _, env := range cfg.Account.Passwords { for _, env := range cfg.Account.Passwords {

View file

@ -109,6 +109,7 @@ var (
//utils.TestnetFlag, //utils.TestnetFlag,
//utils.RinkebyFlag, //utils.RinkebyFlag,
//utils.VMEnableDebugFlag, //utils.VMEnableDebugFlag,
utils.TomoTestnetFlag,
utils.NetworkIdFlag, utils.NetworkIdFlag,
utils.RPCCORSDomainFlag, utils.RPCCORSDomainFlag,
utils.RPCVirtualHostsFlag, utils.RPCVirtualHostsFlag,

View file

@ -139,6 +139,10 @@ var (
Name: "testnet", Name: "testnet",
Usage: "Ropsten network: pre-configured proof-of-work test network", Usage: "Ropsten network: pre-configured proof-of-work test network",
} }
TomoTestnetFlag = cli.BoolFlag{
Name: "tomo-testnet",
Usage: "Tomo test network",
}
RinkebyFlag = cli.BoolFlag{ RinkebyFlag = cli.BoolFlag{
Name: "rinkeby", Name: "rinkeby",
Usage: "Rinkeby network: pre-configured proof-of-authority test network", Usage: "Rinkeby network: pre-configured proof-of-authority test network",

View file

@ -16,3 +16,5 @@ const (
LimitThresholdNonceInQueue = 10 LimitThresholdNonceInQueue = 10
MinGasPrice = 2500 MinGasPrice = 2500
) )
var IsTestnet bool = false

View file

@ -45,8 +45,8 @@ import (
) )
const ( const (
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
M2ByteLength = 4 M2ByteLength = 4
) )
type Masternode struct { type Masternode struct {
@ -476,9 +476,13 @@ func whoIsCreator(snap *Snapshot, header *types.Header) (common.Address, error)
func (c *Posv) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (int, int, int, bool, error) { func (c *Posv) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (int, int, int, bool, error) {
masternodes := c.GetMasternodes(chain, parent) masternodes := c.GetMasternodes(chain, parent)
if common.IsTestnet {
// Only three mns for tomo testnet.
masternodes = masternodes[:3]
}
snap, err := c.GetSnapshot(chain, parent) snap, err := c.GetSnapshot(chain, parent)
if err != nil { if err != nil {
log.Error("Failed when trying to commit new work", "err", err) log.Warn("Failed when trying to commit new work", "err", err)
return 0, -1, -1, false, err return 0, -1, -1, false, err
} }
if len(masternodes) == 0 { if len(masternodes) == 0 {
@ -499,7 +503,7 @@ func (c *Posv) YourTurn(chain consensus.ChainReader, parent *types.Header, signe
log.Info("Masternodes cycle info", "number of masternodes", len(masternodes), "previous", pre, "position", preIndex, "current", signer, "position", curIndex) log.Info("Masternodes cycle info", "number of masternodes", len(masternodes), "previous", pre, "position", preIndex, "current", signer, "position", curIndex)
} }
for i, s := range masternodes { for i, s := range masternodes {
fmt.Printf("%d - %s\n", i, s.String()) log.Info("%d - %s\n", i, s.String())
} }
if (preIndex+1)%len(masternodes) == curIndex { if (preIndex+1)%len(masternodes) == curIndex {
return len(masternodes), preIndex, curIndex, true, nil return len(masternodes), preIndex, curIndex, true, nil

View file

@ -85,7 +85,7 @@ func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, m
// Add tx signed to local tx pool. // Add tx signed to local tx pool.
err = pool.AddLocal(txSigned) err = pool.AddLocal(txSigned)
if err != nil { if err != nil {
log.Error("Fail to add tx sign to local pool.", "error", err, "number", block.NumberU64(), "hash", block.Hash().Hex(), "from", account.Address, "nonce", nonce) log.Warn("Fail to add tx sign to local pool.", "error", err, "number", block.NumberU64(), "hash", block.Hash().Hex(), "from", account.Address, "nonce", nonce)
} }
// Create secret tx. // Create secret tx.

View file

@ -127,11 +127,11 @@ type BlockChain struct {
bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format bodyRLPCache *lru.Cache // Cache for the most recent block bodies in RLP encoded format
blockCache *lru.Cache // Cache for the most recent entire blocks blockCache *lru.Cache // Cache for the most recent entire blocks
futureBlocks *lru.Cache // future blocks are blocks added for later processing futureBlocks *lru.Cache // future blocks are blocks added for later processing
resultProcess *lru.Cache // Cache for processed blocks resultProcess *lru.Cache // Cache for processed blocks
calculatingBlock *lru.Cache // Cache for processing blocks calculatingBlock *lru.Cache // Cache for processing blocks
downloadingBlock *lru.Cache // Cache for downloading blocks (avoid duplication from fetcher) downloadingBlock *lru.Cache // Cache for downloading blocks (avoid duplication from fetcher)
quit chan struct{} // blockchain quit channel quit chan struct{} // blockchain quit channel
running int32 // running must be called atomically running int32 // running must be called atomically
// procInterrupt must be atomically called // procInterrupt must be atomically called
procInterrupt int32 // interrupt signaler for block processing procInterrupt int32 // interrupt signaler for block processing
wg sync.WaitGroup // chain processing wait group for shutting down wg sync.WaitGroup // chain processing wait group for shutting down

View file

@ -1171,7 +1171,7 @@ func (pool *TxPool) demoteUnexecutables() {
if list.Len() > 0 && list.txs.Get(nonce) == nil { if list.Len() > 0 && list.txs.Get(nonce) == nil {
for _, tx := range list.Cap(0) { for _, tx := range list.Cap(0) {
hash := tx.Hash() hash := tx.Hash()
log.Error("Demoting invalidated transaction", "hash", hash) log.Warn("Demoting invalidated transaction", "hash", hash)
pool.enqueueTx(hash, tx) pool.enqueueTx(hash, tx)
} }
} }

View file

@ -355,7 +355,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
currentHeader := eth.blockchain.CurrentHeader() currentHeader := eth.blockchain.CurrentHeader()
snap, err := c.GetSnapshot(eth.blockchain, currentHeader) snap, err := c.GetSnapshot(eth.blockchain, currentHeader)
if err != nil { if err != nil {
log.Error("Can't get snapshot with current header ", "number", currentHeader.Number, "hash", currentHeader.Hash().Hex()) log.Error("Can't get snapshot with current header ", "number", currentHeader.Number, "hash", currentHeader.Hash().Hex(), "err", err)
return false return false
} }
if _, ok := snap.Signers[address]; ok { if _, ok := snap.Signers[address]; ok {

View file

@ -295,7 +295,7 @@ func (d *Downloader) UnregisterPeer(id string) error {
logger := log.New("peer", id) logger := log.New("peer", id)
logger.Trace("Unregistering sync peer") logger.Trace("Unregistering sync peer")
if err := d.peers.Unregister(id); err != nil { if err := d.peers.Unregister(id); err != nil {
logger.Error("Failed to unregister sync peer", "err", err) logger.Warn("Failed to unregister sync peer", "err", err)
return err return err
} }
d.queue.Revoke(id) d.queue.Revoke(id)

View file

@ -205,7 +205,7 @@ func (pm *ProtocolManager) removePeer(id string) {
// Unregister the peer from the downloader and Ethereum peer set // Unregister the peer from the downloader and Ethereum peer set
pm.downloader.UnregisterPeer(id) pm.downloader.UnregisterPeer(id)
if err := pm.peers.Unregister(id); err != nil { if err := pm.peers.Unregister(id); err != nil {
log.Error("Peer removal failed", "peer", id, "err", err) log.Warn("Peer removal failed", "peer", id, "err", err)
} }
// Hard disconnect at the networking layer // Hard disconnect at the networking layer
if peer != nil { if peer != nil {

View file

@ -17,7 +17,7 @@
} }
}, },
"nonce": "0x0", "nonce": "0x0",
"timestamp": "0x5c107ff8", "timestamp": "0x5c1358f5",
"extraData": "0x00000000000000000000000000000000000000000000000000000000000000001b82c4bf317fcafe3d77e8b444c82715d216afe845b7bd987fa22c9bac89b71f0ded03f6e150ba31ad670b2b166684657ffff95f4810380ae7381e9bce41231d5dd8cdd7499e418b648c00af75d184a2f9aba09a6fa4a46fb1a6a3919b027d9cac5aa6890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x00000000000000000000000000000000000000000000000000000000000000001b82c4bf317fcafe3d77e8b444c82715d216afe845b7bd987fa22c9bac89b71f0ded03f6e150ba31ad670b2b166684657ffff95f4810380ae7381e9bce41231d5dd8cdd7499e418b648c00af75d184a2f9aba09a6fa4a46fb1a6a3919b027d9cac5aa6890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760", "gasLimit": "0x47b760",
"difficulty": "0x1", "difficulty": "0x1",
@ -119,4 +119,4 @@
"number": "0x0", "number": "0x0",
"gasUsed": "0x0", "gasUsed": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000" "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
} }

View file

@ -497,9 +497,9 @@ func (self *worker) commitNewWork() {
if self.config.Posv != nil { if self.config.Posv != nil {
// get masternodes set from latest checkpoint // get masternodes set from latest checkpoint
c := self.engine.(*posv.Posv) c := self.engine.(*posv.Posv)
len, preIndex, curIndex, ok, err := c.YourTurn(self.chain, parent.Header(),self.coinbase) len, preIndex, curIndex, ok, err := c.YourTurn(self.chain, parent.Header(), self.coinbase)
if err != nil { if err != nil {
log.Error("Failed when trying to commit new work", "err", err) log.Warn("Failed when trying to commit new work", "err", err)
return return
} }
if !ok { if !ok {

View file

@ -23,7 +23,7 @@ import (
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 1 // Minor version component of the current release VersionMinor = 1 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release VersionPatch = 1 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string VersionMeta = "stable" // Version metadata to append to the version string
) )