diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-12-13 10:45:29 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | b59955ee9da30f2eb2652a7a38aa58cd7e07be56 (patch) | |
tree | 02298d0637a3799106dd229f04e151138d06d281 | |
parent | 5d8800ff15319f0588b37959385a6e235cffd72e (diff) | |
download | dexon-b59955ee9da30f2eb2652a7a38aa58cd7e07be56.tar.gz dexon-b59955ee9da30f2eb2652a7a38aa58cd7e07be56.tar.zst dexon-b59955ee9da30f2eb2652a7a38aa58cd7e07be56.zip |
dex, cmd: Add DMoment to command line (#87)
-rw-r--r-- | cmd/gdex/main.go | 1 | ||||
-rw-r--r-- | cmd/utils/flags.go | 14 | ||||
-rw-r--r-- | dex/backend.go | 8 | ||||
-rw-r--r-- | dex/config.go | 3 |
4 files changed, 20 insertions, 6 deletions
diff --git a/cmd/gdex/main.go b/cmd/gdex/main.go index 6d495ba11..f4e9bf994 100644 --- a/cmd/gdex/main.go +++ b/cmd/gdex/main.go @@ -98,6 +98,7 @@ var ( utils.MaxPeersFlag, utils.MaxPendingPeersFlag, utils.BlockProposerEnabledFlag, + utils.ConsensusDMomentFlag, utils.MiningEnabledFlag, utils.MinerThreadsFlag, utils.MinerLegacyThreadsFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index ecd36eacf..da820a544 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -325,6 +325,10 @@ var ( Name: "bp", Usage: "Enable block proposer mode (node set)", } + ConsensusDMomentFlag = cli.Uint64Flag{ + Name: "dmoment", + Usage: "Set the DMoment of DEXON Consensus (unix timestamp)", + } // Miner settings MiningEnabledFlag = cli.BoolFlag{ Name: "mine", @@ -1260,6 +1264,16 @@ func SetDexConfig(ctx *cli.Context, stack *node.Node, cfg *dex.Config) { if gen := ctx.GlobalInt(TrieCacheGenFlag.Name); gen > 0 { state.MaxTrieCacheGen = uint16(gen) } + if ctx.GlobalIsSet(ConsensusDMomentFlag.Name) { + cfg.DMoment = int64(ctx.GlobalUint64(ConsensusDMomentFlag.Name)) + } else { + // TODO(jimmy): default DMoment should be set based on networkId. + now := time.Now() + cfg.DMoment = time.Date( + now.Year(), now.Month(), now.Day(), + now.Hour(), now.Minute(), (now.Second()/5+1)*5, + 0, now.Location()).Unix() + } } // SetDashboardConfig applies dashboard related command line flags to the config. diff --git a/dex/backend.go b/dex/backend.go index 8153dc2ed..5ea30b1a9 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -166,12 +166,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { privKey := coreEcdsa.NewPrivateKeyFromECDSA(config.PrivateKey) - // TODO(w): set this correctly in config. - now := time.Now() - dMoment := time.Date( - now.Year(), now.Month(), now.Day(), - now.Hour(), now.Minute(), (now.Second()/5+1)*5, - 0, now.Location()) + dMoment := time.Unix(config.DMoment, int64(0)) + log.Info("DEXON Consensus DMoment", "time", dMoment) dex.consensus = dexCore.NewConsensus(dMoment, dex.app, dex.governance, blockdb.NewDatabase(chainDb), dex.network, privKey, log.Root()) diff --git a/dex/config.go b/dex/config.go index 5fa7d87e8..404be2fb0 100644 --- a/dex/config.go +++ b/dex/config.go @@ -114,4 +114,7 @@ type Config struct { EWASMInterpreter string // Type of the EVM interpreter ("" for default) EVMInterpreter string + + // Dexon options + DMoment int64 } |