Skip to content

Commit

Permalink
Merge pull request #3 from tungng98/feat/new-testnet
Browse files Browse the repository at this point in the history
New testnet configuration
  • Loading branch information
tungng98 authored Aug 2, 2024
2 parents 722d85a + 927ce66 commit 95d271e
Show file tree
Hide file tree
Showing 30 changed files with 438 additions and 704 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

GOBIN = $(shell pwd)/build/bin
GOFMT = gofmt
GO ?= 1.13.1
GO ?= 1.13.15
GO_PACKAGES = .
GO_FILES := $(shell find $(shell go list -f '{{.Dir}}' $(GO_PACKAGES)) -name \*.go)

Expand Down
24 changes: 17 additions & 7 deletions cmd/tomo/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
"bufio"
"errors"
"fmt"
"gopkg.in/urfave/cli.v1"
"io"
"math/big"
"os"
"reflect"
"strings"
"unicode"

"gopkg.in/urfave/cli.v1"

"github.com/naoina/toml"
"github.com/tomochain/tomochain/cmd/utils"
"github.com/tomochain/tomochain/common"
Expand Down Expand Up @@ -156,14 +157,23 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
// Check testnet is enable.
if ctx.GlobalBool(utils.TomoTestnetFlag.Name) {
common.IsTestnet = true
common.TRC21IssuerSMC = common.TRC21IssuerSMCTestNet
cfg.Eth.NetworkId = 89
common.RelayerRegistrationSMC = common.RelayerRegistrationSMCTestnet
common.TIPTRC21Fee = common.TIPTomoXTestnet
common.TIPSigning = big.NewInt(0)
common.TIPRandomize = big.NewInt(0)

// Testnet hard fork blocks
common.TIP2019Block = big.NewInt(0)
common.BlackListHFNumber = uint64(0)
common.TIPSigningBlock = big.NewInt(0)
common.TIPRandomizeBlock = big.NewInt(0)
common.BlackListHFBlock = uint64(0)
common.TIPTRC21FeeBlock = big.NewInt(0)
common.TIPTomoXBlock = big.NewInt(0)
common.TIPTomoXLendingBlock = big.NewInt(0)
common.TIPTomoXCancellationFeeBlock = big.NewInt(0)

// Backward-compability for current testnet
// TODO: Remove if start new testnet again
common.LendingRegistrationSMC = "0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8"
common.RelayerRegistrationSMC = "0xA1996F69f47ba14Cb7f661010A7C31974277958c"
common.TomoXListingSMC = common.HexToAddress("0x14B2Bf043b9c31827A472CE4F94294fE9a6277e0")
}

// Rewound
Expand Down
5 changes: 3 additions & 2 deletions cmd/tomo/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package main

import (
"github.com/tomochain/tomochain/core/rawdb"
"io/ioutil"
"math/big"
"os"
"path/filepath"
"testing"

"github.com/tomochain/tomochain/core/rawdb"

"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/core"
)
Expand Down Expand Up @@ -88,7 +89,7 @@ func TestDAOForkBlockNewChain(t *testing.T) {
expectVote bool
}{
// Test DAO Default Mainnet
// {"", params.TomoMainnetChainConfig.DAOForkBlock, false},
// {"", params.VicMainnetChainConfig.DAOForkBlock, false},
// test DAO Init Old Privnet
{daoOldGenesis, nil, false},
// test DAO Default No Fork Privnet
Expand Down
29 changes: 6 additions & 23 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/tomochain/tomochain/accounts"
"github.com/tomochain/tomochain/accounts/keystore"
"github.com/tomochain/tomochain/cmd/utils"
"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/consensus/posv"
"github.com/tomochain/tomochain/console"
"github.com/tomochain/tomochain/core"
Expand Down Expand Up @@ -297,19 +296,10 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
if _, ok := ethereum.Engine().(*posv.Posv); ok {
go func() {
started := false
ok := false
slaveMode := ctx.GlobalIsSet(utils.TomoSlaveModeFlag.Name)
var err error
if common.IsTestnet {
ok, err = ethereum.ValidateMasternodeTestnet()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
} else {
ok, err = ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
ok, err := ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
if ok {
if slaveMode {
Expand Down Expand Up @@ -338,16 +328,9 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
defer close(core.CheckpointCh)
for range core.CheckpointCh {
log.Info("Checkpoint!!! It's time to reconcile node's state...")
if common.IsTestnet {
ok, err = ethereum.ValidateMasternodeTestnet()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
} else {
ok, err = ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
ok, err := ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
if !ok {
if started {
Expand Down
6 changes: 3 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,15 +624,15 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls = strings.Split(ctx.GlobalString(BootnodesFlag.Name), ",")
}
// case ctx.GlobalBool(TestnetFlag.Name):
// urls = params.TestnetBootnodes
// urls = params.RostenBootnodes
// case ctx.GlobalBool(RinkebyFlag.Name):
// urls = params.RinkebyBootnodes
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
case !ctx.GlobalIsSet(BootnodesFlag.Name):
urls = params.MainnetBootnodes
urls = params.VicMainnetBootnodes
case ctx.GlobalBool(TomoTestnetFlag.Name):
urls = params.TestnetBootnodes
urls = params.VicTestnetBootnodes
}
cfg.BootstrapNodes = make([]*discover.Node, 0, len(urls))
for _, url := range urls {
Expand Down
84 changes: 43 additions & 41 deletions common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,60 @@ const (
EpocBlockOpening = 850
EpocBlockRandomize = 900
MaxMasternodes = 150
MinimunMinerBlockPerEpoch = 1
LimitPenaltyEpoch = 4
BlocksPerYear = uint64(15768000)
LimitThresholdNonceInQueue = 10
DefaultMinGasPrice = 250000000
MergeSignRange = 15
RangeReturnSigner = 150
MinimunMinerBlockPerEpoch = 1

DefaultMinGasPrice = 250000000

IgnoreSignerCheckBlock = uint64(14458500)
OneYear = uint64(365 * 86400)
OneYear = uint64(31536000)
BlocksPerYear = uint64(15768000)
LiquidateLendingTradeBlock = uint64(100)
)

var Rewound = uint64(0)

// hardforks
var TIP2019Block = big.NewInt(1050000)
var TIPSigning = big.NewInt(3000000)
var TIPRandomize = big.NewInt(3464000)
var BlackListHFNumber = uint64(9349100)
var TIPTomoX = big.NewInt(20581700)
var TIPTomoXLending = big.NewInt(21430200)
var TIPTomoXCancellationFee = big.NewInt(30915660)
var TIPTomoXTestnet = big.NewInt(0)
var IsTestnet bool = false
var StoreRewardFolder string
var RollbackHash Hash
var BasePrice = big.NewInt(1000000000000000000) // 1
var RelayerLockedFund = big.NewInt(20000) // 20000 TOMO
var RelayerFee = big.NewInt(1000000000000000) // 0.001
var TomoXBaseFee = big.NewInt(10000) // 1 / TomoXBaseFee
var RelayerCancelFee = big.NewInt(100000000000000) // 0.0001
var TomoXBaseCancelFee = new(big.Int).Mul(TomoXBaseFee, big.NewInt(10)) // 1/ (TomoXBaseFee *10)
var RelayerLendingFee = big.NewInt(10000000000000000) // 0.01
var RelayerLendingCancelFee = big.NewInt(1000000000000000) // 0.001
var BaseLendingInterest = big.NewInt(100000000) // 1e8
var (
TIP2019Block = big.NewInt(1050000)
TIPSigningBlock = big.NewInt(3000000)
TIPRandomizeBlock = big.NewInt(3464000)
BlackListHFBlock = uint64(9349100)
TIPTRC21FeeBlock = big.NewInt(13523400)
TIPTomoXBlock = big.NewInt(20581700)
TIPTomoXLendingBlock = big.NewInt(21430200)
TIPTomoXCancellationFeeBlock = big.NewInt(30915660)

IsTestnet bool = false
StoreRewardFolder string
RollbackHash Hash
LimitTimeFinality = uint64(30) // limit in 30 block

BasePrice = big.NewInt(1000000000000000000) // 1
BaseLendingInterest = big.NewInt(100000000) // 1e8
RelayerLockedFund = big.NewInt(20000) // 20000 TOMO
RelayerFee = big.NewInt(1000000000000000) // 0.001
RelayerCancelFee = big.NewInt(100000000000000) // 0.0001
RelayerLendingFee = big.NewInt(10000000000000000) // 0.01
RelayerLendingCancelFee = big.NewInt(1000000000000000) // 0.001
TomoXBaseFee = big.NewInt(10000) // 1 / TomoXBaseFee
TomoXBaseCancelFee = new(big.Int).Mul(TomoXBaseFee, big.NewInt(10)) // 1/ (TomoXBaseFee *10)

MinGasPrice = big.NewInt(DefaultMinGasPrice)
TRC21GasPriceBefore = big.NewInt(2500)
TRC21GasPrice = big.NewInt(250000000)
RateTopUp = big.NewInt(90) // 90%
BaseTopUp = big.NewInt(100)
BaseRecall = big.NewInt(100)

RelayerRegistrationSMC = "0x16c63b79f9C8784168103C0b74E6A59EC2de4a02"
LendingRegistrationSMC = "0x7d761afd7ff65a79e4173897594a194e3c506e57"
TRC21IssuerSMC = HexToAddress("0x8c0faeb5C6bEd2129b8674F262Fd45c4e9468bee")
TomoXListingSMC = HexToAddress("0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53")
)

var MinGasPrice = big.NewInt(DefaultMinGasPrice)
var RelayerRegistrationSMC = "0x16c63b79f9C8784168103C0b74E6A59EC2de4a02"
var RelayerRegistrationSMCTestnet = "0xA1996F69f47ba14Cb7f661010A7C31974277958c"
var LendingRegistrationSMC = "0x7d761afd7ff65a79e4173897594a194e3c506e57"
var LendingRegistrationSMCTestnet = "0x28d7fC2Cf5c18203aaCD7459EFC6Af0643C97bE8"
var TRC21IssuerSMCTestNet = HexToAddress("0x0E2C88753131CE01c7551B726b28BFD04e44003F")
var TRC21IssuerSMC = HexToAddress("0x8c0faeb5C6bEd2129b8674F262Fd45c4e9468bee")
var TomoXListingSMC = HexToAddress("0xDE34dD0f536170993E8CFF639DdFfCF1A85D3E53")
var TomoXListingSMCTestNet = HexToAddress("0x14B2Bf043b9c31827A472CE4F94294fE9a6277e0")
var TRC21GasPriceBefore = big.NewInt(2500)
var TRC21GasPrice = big.NewInt(250000000)
var RateTopUp = big.NewInt(90) // 90%
var BaseTopUp = big.NewInt(100)
var BaseRecall = big.NewInt(100)
var Blacklist = map[Address]bool{
HexToAddress("0x5248bfb72fd4f234e062d3e9bb76f08643004fcd"): true,
HexToAddress("0x5ac26105b35ea8935be382863a70281ec7a985e9"): true,
Expand Down Expand Up @@ -128,5 +132,3 @@ var Blacklist = map[Address]bool{
HexToAddress("0xe187cf86c2274b1f16e8225a7da9a75aba4f1f5f"): true,
HexToAddress("0x0000000000000000000000000000000000000011"): true,
}
var TIPTRC21Fee = big.NewInt(13523400)
var LimitTimeFinality = uint64(30) // limit in 30 block
18 changes: 6 additions & 12 deletions consensus/posv/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
package posv

import (
"math/big"

"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/consensus"
"github.com/tomochain/tomochain/core/types"
"github.com/tomochain/tomochain/rpc"
"math/big"
)

// API is a user facing RPC API to allow controlling the signer and voting
Expand Down Expand Up @@ -102,16 +103,9 @@ func (api *API) NetworkInformation() NetworkInformation {
info := NetworkInformation{}
info.NetworkId = api.chain.Config().ChainId
info.TomoValidatorAddress = common.HexToAddress(common.MasternodeVotingSMC)
if common.IsTestnet {
info.LendingAddress = common.HexToAddress(common.LendingRegistrationSMCTestnet)
info.RelayerRegistrationAddress = common.HexToAddress(common.RelayerRegistrationSMCTestnet)
info.TomoXListingAddress = common.TomoXListingSMCTestNet
info.TomoZAddress = common.TRC21IssuerSMCTestNet
} else {
info.LendingAddress = common.HexToAddress(common.LendingRegistrationSMC)
info.RelayerRegistrationAddress = common.HexToAddress(common.RelayerRegistrationSMC)
info.TomoXListingAddress = common.TomoXListingSMC
info.TomoZAddress = common.TRC21IssuerSMC
}
info.LendingAddress = common.HexToAddress(common.LendingRegistrationSMC)
info.RelayerRegistrationAddress = common.HexToAddress(common.RelayerRegistrationSMC)
info.TomoXListingAddress = common.TomoXListingSMC
info.TomoZAddress = common.TRC21IssuerSMC
return info
}
28 changes: 4 additions & 24 deletions consensus/posv/posv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/tomochain/tomochain/tomox/tradingstate"
"github.com/tomochain/tomochain/tomoxlending/lendingstate"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"
"io/ioutil"
"math/big"
"math/rand"
Expand All @@ -34,6 +31,10 @@ import (
"sync"
"time"

"github.com/tomochain/tomochain/tomox/tradingstate"
"github.com/tomochain/tomochain/tomoxlending/lendingstate"
"gopkg.in/karalabe/cookiejar.v2/collections/prque"

lru "github.com/hashicorp/golang-lru"
"github.com/tomochain/tomochain/accounts"
"github.com/tomochain/tomochain/common"
Expand Down Expand Up @@ -348,9 +349,6 @@ func (c *Posv) verifyHeaderWithCache(chain consensus.ChainReader, header *types.
// looking those up from the database. This is useful for concurrently verifying
// a batch of new headers.
func (c *Posv) verifyHeader(chain consensus.ChainReader, header *types.Header, parents []*types.Header, fullVerify bool) error {
if common.IsTestnet {
fullVerify = false
}
if header.Number == nil {
return errUnknownBlock
}
Expand Down Expand Up @@ -581,15 +579,6 @@ 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) {
masternodes := c.GetMasternodes(chain, parent)

if common.IsTestnet {
// Only three mns hard code for tomo testnet.
masternodes = []common.Address{
common.HexToAddress("0xfFC679Dcdf444D2eEb0491A998E7902B411CcF20"),
common.HexToAddress("0xd76fd76F7101811726DCE9E43C2617706a4c45c8"),
common.HexToAddress("0x8A97753311aeAFACfd76a68Cf2e2a9808d3e65E8"),
}
}

snap, err := c.GetSnapshot(chain, parent)
if err != nil {
log.Warn("Failed when trying to commit new work", "err", err)
Expand Down Expand Up @@ -1279,15 +1268,6 @@ func Hop(len, pre, cur int) int {
func (c *Posv) CheckMNTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) bool {
masternodes := c.GetMasternodes(chain, parent)

if common.IsTestnet {
// Only three mns hard code for tomo testnet.
masternodes = []common.Address{
common.HexToAddress("0xfFC679Dcdf444D2eEb0491A998E7902B411CcF20"),
common.HexToAddress("0xd76fd76F7101811726DCE9E43C2617706a4c45c8"),
common.HexToAddress("0x8A97753311aeAFACfd76a68Cf2e2a9808d3e65E8"),
}
}

snap, err := c.GetSnapshot(chain, parent)
if err != nil {
log.Warn("Failed when trying to commit new work", "err", err)
Expand Down
9 changes: 5 additions & 4 deletions contracts/tests/Inherited_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package tests

import (
"fmt"
"math/big"
"os"
"testing"

"github.com/tomochain/tomochain/accounts/abi/bind"
"github.com/tomochain/tomochain/accounts/abi/bind/backends"
"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/crypto"
"github.com/tomochain/tomochain/log"
"math/big"
"os"
"testing"
)

var (
Expand All @@ -22,7 +23,7 @@ func TestPriceFeed(t *testing.T) {
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false)))
glogger.Verbosity(log.LvlTrace)
log.Root().SetHandler(glogger)
common.TIPTomoXCancellationFee = big.NewInt(0)
common.TIPTomoXCancellationFeeBlock = big.NewInt(0)
// init genesis
contractBackend := backends.NewSimulatedBackend(core.GenesisAlloc{
mainAddr: {Balance: big.NewInt(0).Mul(big.NewInt(10000000000000), big.NewInt(10000000000000))},
Expand Down
Loading

0 comments on commit 95d271e

Please sign in to comment.