Skip to content

Commit

Permalink
feat(nft): refactoring settings and config
Browse files Browse the repository at this point in the history
Signed-off-by: xiaobo <[email protected]>
  • Loading branch information
peterwillcn authored and RainFallsSilent committed Oct 28, 2022
1 parent f4ecbff commit e308e77
Show file tree
Hide file tree
Showing 177 changed files with 2,683 additions and 4,368 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ elastos*/
/tmp
/go.sum
keystore
goheader
*.out
*.test
benchmark/process/run-to-height
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GOVER := $(shell go version)
VERSION := $(shell git describe --abbrev=4 --dirty --always --tags)
BUILD = go build -ldflags "-X main.Version=$(VERSION) -X 'main.GoVersion=$(GOVER)'" #-race
BUILD = go build -ldflags "-X main.Version=$(VERSION) -X 'main.GoVersion=$(GOVER)'"

DEV_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
DEV_VERSION := $(shell git rev-list HEAD -n 1 | cut -c 1-8)
Expand Down
5 changes: 3 additions & 2 deletions benchmark/common/tx/fixamontassigner.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/elastos/Elastos.ELA/account"
"github.com/elastos/Elastos.ELA/benchmark/common/utils"
"github.com/elastos/Elastos.ELA/common"
"github.com/elastos/Elastos.ELA/common/config"
"github.com/elastos/Elastos.ELA/core"
common2 "github.com/elastos/Elastos.ELA/core/types/common"
"github.com/elastos/Elastos.ELA/core/types/interfaces"
"github.com/elastos/Elastos.ELA/core/types/outputpayload"
Expand Down Expand Up @@ -38,8 +38,9 @@ func (a *fixAmountAssigner) SignAndChange(tx interfaces.Transaction) error {
for _, o := range tx.Outputs() {
o.Value = defaultAmount
}
ELAAssetID, _ := common.Uint256FromHexString(core.ELAAssetID)
tx.SetOutputs(append(tx.Outputs(), &common2.Output{
AssetID: config.ELAAssetID,
AssetID: *ELAAssetID,
Value: a.utxo.Value -
defaultAmount*common.Fixed64(len(tx.Outputs())) - defaultFee,
OutputLock: 0,
Expand Down
7 changes: 5 additions & 2 deletions benchmark/common/tx/transferasset.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ package tx
import (
"github.com/elastos/Elastos.ELA/account"
"github.com/elastos/Elastos.ELA/benchmark/common/utils"
"github.com/elastos/Elastos.ELA/common/config"
"github.com/elastos/Elastos.ELA/common"
"github.com/elastos/Elastos.ELA/core"
common2 "github.com/elastos/Elastos.ELA/core/types/common"
"github.com/elastos/Elastos.ELA/core/types/functions"
"github.com/elastos/Elastos.ELA/core/types/interfaces"
Expand Down Expand Up @@ -41,9 +42,11 @@ func (g *transferAssetGenerator) Generate() interfaces.Transaction {
0,
nil,
)
ELAAssetID, _ := common.Uint256FromHexString(core.ELAAssetID)
for _, v := range g.account {

txn.SetOutputs(append(txn.Outputs(), &common2.Output{
AssetID: config.ELAAssetID,
AssetID: *ELAAssetID,
Value: 0, // assign later
OutputLock: 0,
ProgramHash: v.ProgramHash,
Expand Down
119 changes: 39 additions & 80 deletions benchmark/sync/synctobestheight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package sync

import (
"bytes"
"flag"
"fmt"
"os"
"os/exec"
Expand All @@ -19,10 +18,11 @@ import (
"time"

"github.com/elastos/Elastos.ELA/blockchain"
cmdcom "github.com/elastos/Elastos.ELA/cmd/common"
"github.com/elastos/Elastos.ELA/common"
"github.com/elastos/Elastos.ELA/common/config"
"github.com/elastos/Elastos.ELA/common/config/settings"
"github.com/elastos/Elastos.ELA/common/log"
"github.com/elastos/Elastos.ELA/core/checkpoint"
"github.com/elastos/Elastos.ELA/core/types"
crstate "github.com/elastos/Elastos.ELA/cr/state"
"github.com/elastos/Elastos.ELA/dpos/state"
Expand Down Expand Up @@ -76,42 +76,43 @@ func Benchmark_Sync_ToBestHeight(b *testing.B) {

func startDstNode() {
// Enable profiling server if requested.
if dstSettings.Config().ProfilePort != 0 {
go utils.StartPProf(dstSettings.Config().ProfilePort,
dstSettings.Config().ProfileHost)
if dstSettings.ProfilePort != 0 {
go utils.StartPProf(dstSettings.ProfilePort,
dstSettings.ProfileHost)
}

flagDataDir := dstContext.String("datadir")
dataDir := filepath.Join(flagDataDir, dataPath)
dstSettings.Params().CkpManager.SetDataPath(
filepath.Join(dataDir, checkpointPath))
dstSettings.Params().CkpManager.SetNeedSave(true)

ckpManager := checkpoint.NewManager(dstSettings)
ckpManager.SetDataPath(filepath.Join(dataDir, checkpointPath))

var interrupt = signal.NewInterrupt()

ledger := blockchain.Ledger{}

// Initializes the foundation address
blockchain.FoundationAddress = dstSettings.Params().Foundation
FoundationAddress, _ := common.Uint168FromAddress(dstSettings.FoundationAddress)
blockchain.FoundationAddress = *FoundationAddress

chainStore, err := blockchain.NewChainStore(dataDir, dstSettings.Params())
chainStore, err := blockchain.NewChainStore(dataDir, dstSettings)
if err != nil {
logger.Error(err)
return
}
defer chainStore.Close()
ledger.Store = chainStore

txMemPool := mempool.NewTxPool(dstSettings.Params())
blockMemPool := mempool.NewBlockPool(dstSettings.Params())
txMemPool := mempool.NewTxPool(dstSettings, ckpManager)
blockMemPool := mempool.NewBlockPool(dstSettings)
blockMemPool.Store = chainStore

blockchain.DefaultLedger = &ledger

committee := crstate.NewCommittee(dstSettings.Params())
committee := crstate.NewCommittee(dstSettings, ckpManager)
ledger.Committee = committee

arbiters, err := state.NewArbitrators(dstSettings.Params(), committee,
arbiters, err := state.NewArbitrators(dstSettings, committee,
func(programHash common.Uint168) (common.Fixed64,
error) {
amount := common.Fixed64(0)
Expand All @@ -125,14 +126,15 @@ func startDstNode() {
}
return amount, nil
}, nil, nil,
nil, nil, nil, nil)
nil, nil, nil, nil,
ckpManager)
if err != nil {
logger.Error(err)
return
}
ledger.Arbitrators = arbiters

chain, err := blockchain.New(chainStore, dstSettings.Params(), arbiters.State, committee)
chain, err := blockchain.New(chainStore, dstSettings, arbiters.State, committee, ckpManager)
if err != nil {
logger.Error(err)
return
Expand All @@ -142,7 +144,7 @@ func startDstNode() {
return
}
if err := chain.MigrateOldDB(interrupt.C, func(uint32) {},
func() {}, dataDir, dstSettings.Params()); err != nil {
func() {}, dataDir, dstSettings); err != nil {
logger.Error(err)
return
}
Expand All @@ -168,8 +170,8 @@ func startDstNode() {
route := routes.New(routesCfg)
server, err := elanet.NewServer(dataDir, &elanet.Config{
Chain: chain,
ChainParams: dstSettings.Params(),
PermanentPeers: dstSettings.Params().PermanentPeers,
ChainParams: dstSettings,
PermanentPeers: dstSettings.PermanentPeers,
TxMemPool: txMemPool,
BlockMemPool: blockMemPool,
Routes: route,
Expand All @@ -196,25 +198,24 @@ func startDstNode() {

wal := wallet.NewWallet()
wallet.Store = chainStore
wallet.ChainParam = dstSettings.Params()
wallet.ChainParam = dstSettings
wallet.Chain = chain

dstSettings.Params().CkpManager.Register(wal)
ckpManager.Register(wal)

servers.Compile = "benchmark"
servers.Config = dstSettings.Config()
servers.ChainParams = dstSettings.Params()
servers.ChainParams = dstSettings
servers.Chain = chain
servers.Store = chainStore
servers.TxMemPool = txMemPool
servers.Server = server
servers.Arbiters = arbiters
servers.Wallet = wal
servers.Pow = pow.NewService(&pow.Config{
PayToAddr: dstSettings.Config().PowConfiguration.PayToAddr,
MinerInfo: dstSettings.Config().PowConfiguration.MinerInfo,
PayToAddr: dstSettings.PowConfiguration.PayToAddr,
MinerInfo: dstSettings.PowConfiguration.MinerInfo,
Chain: chain,
ChainParams: dstSettings.Params(),
ChainParams: dstSettings,
TxMemPool: txMemPool,
BlkMemPool: blockMemPool,
BroadcastBlock: func(block *types.Block) {
Expand Down Expand Up @@ -276,55 +277,11 @@ func getSrcRunArgs() []string {
}
}

func newCliContext(st *settings.Settings) *cli.Context {
ctx := cli.NewContext(nil, newFlagSet(st), nil)
ctx.Set("magic", magic)
ctx.Set("conf", configPath)
ctx.Set("datadir", dstDataDir)
ctx.Set("peers", getPeerAddr(srcNodePort))
ctx.Set("port", dstNodePort)
ctx.Set("arbiter", "false")
ctx.Set("server", "false")
ctx.Set("automining", "false")
return ctx
}

func initDstSettings() *settings.Settings {
st := settings.NewSettings()
dstContext = newCliContext(st)
st.SetContext(dstContext)
st.SetupConfig()
st.InitParamsValue()
setupLog(dstContext, st)
return st
}

func newFlagSet(st *settings.Settings) *flag.FlagSet {
originFlags := []cli.StringFlag{
cmdcom.ConfigFileFlag,
cmdcom.DataDirFlag,
cmdcom.AccountPasswordFlag,
cmdcom.TestNetFlag,
cmdcom.RegTestFlag,
cmdcom.InfoPortFlag,
cmdcom.RestPortFlag,
cmdcom.WsPortFlag,
cmdcom.InstantBlockFlag,
cmdcom.RPCPortFlag,
}
result := &flag.FlagSet{}

for _, v := range originFlags {
result.String(v.GetName(), v.GetValue(), v.GetUsage())
}

for _, v := range st.Flags() {
if strFlag, ok := v.(cli.StringFlag); ok {
result.String(strFlag.GetName(), strFlag.GetValue(),
strFlag.GetUsage())
}
}
return result
func initDstSettings() *config.Configuration {
setting := settings.NewSettings()
config := setting.SetupConfig()
setupLog(config)
return config
}

func waitForSyncFinish(server elanet.Server, interrupt <-chan struct{}) {
Expand All @@ -345,12 +302,14 @@ out:
}
}

func setupLog(c *cli.Context, s *settings.Settings) {
flagDataDir := c.String("datadir")
func setupLog(s *config.Configuration) {
flagDataDir := config.DataDir
if s.DataDir != "" {
flagDataDir = s.DataDir
}
path := filepath.Join(flagDataDir, dstNodeLogPath)

logger = log.NewDefault(path, uint8(s.Config().PrintLevel),
s.Config().MaxPerLogSize, s.Config().MaxLogsSize)
logger = log.NewDefault(path, uint8(s.PrintLevel),
s.MaxPerLogSize, s.MaxLogsSize)

addrmgr.UseLogger(logger)
connmgr.UseLogger(logger)
Expand Down
16 changes: 10 additions & 6 deletions benchmark/tools/generator/chain/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/elastos/Elastos.ELA/common"
"github.com/elastos/Elastos.ELA/common/config"
"github.com/elastos/Elastos.ELA/common/log"
"github.com/elastos/Elastos.ELA/core"
"github.com/elastos/Elastos.ELA/core/checkpoint"
"github.com/elastos/Elastos.ELA/core/types"
common2 "github.com/elastos/Elastos.ELA/core/types/common"
"github.com/elastos/Elastos.ELA/core/types/interfaces"
Expand All @@ -41,7 +43,7 @@ type TimeCounter struct {
type DataGen struct {
txRepo *TxRepository
chain *blockchain.BlockChain
chainParams *config.Params
chainParams *config.Configuration
pow *pow.Service
txPool *mempool.TxPool
prevBlockHash common.Uint256
Expand Down Expand Up @@ -272,14 +274,15 @@ func LoadDataGen(dataPath string) (*DataGen, error) {

func FromTxRepository(dataDir string, interrupt <-chan struct{},
repo *TxRepository, initFoundationUTXO bool) (*DataGen, error) {
chainParams := generateChainParams(repo.GetFoundationAccount())
chainParams := config.DefaultParams.RegNet()
chain, err := newBlockChain(dataDir, chainParams, interrupt)
ckpManager := checkpoint.NewManager(chainParams)
if err != nil {
return nil, err
}

block := core.GenesisBlock(chainParams.FoundationAddress)
if initFoundationUTXO {
fundTx := chainParams.GenesisBlock.Transactions[0]
fundTx := block.Transactions[0]
repo.SetFoundationUTXO(&common2.UTXO{
TxID: fundTx.Hash(),
Index: 0,
Expand All @@ -292,14 +295,15 @@ func FromTxRepository(dataDir string, interrupt <-chan struct{},
return nil, err
}

txPool := mempool.NewTxPool(chainParams)
txPool := mempool.NewTxPool(chainParams,
ckpManager)
return &DataGen{
txRepo: repo,
chainParams: chainParams,
chain: chain,
txPool: txPool,
foundationAddr: foundationAddr,
prevBlockHash: chainParams.GenesisBlock.Hash(),
prevBlockHash: block.Hash(),
dataDir: dataDir,
pressure: false,
pressureTxSize: 8000000,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/tools/generator/chain/txrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
package chain

import (
"github.com/elastos/Elastos.ELA/core/types/interfaces"
"io"
"math/rand"

"github.com/elastos/Elastos.ELA/account"
"github.com/elastos/Elastos.ELA/benchmark/common/tx"
"github.com/elastos/Elastos.ELA/common"
common2 "github.com/elastos/Elastos.ELA/core/types/common"
"github.com/elastos/Elastos.ELA/core/types/interfaces"
"github.com/elastos/Elastos.ELA/crypto"
)

Expand Down
2 changes: 1 addition & 1 deletion benchmark/tools/generator/chain/txrepository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ package chain

import (
"bytes"
common2 "github.com/elastos/Elastos.ELA/core/types/common"
"math"
"math/rand"
"testing"

"github.com/elastos/Elastos.ELA/account"
"github.com/elastos/Elastos.ELA/common"
common2 "github.com/elastos/Elastos.ELA/core/types/common"
"github.com/stretchr/testify/assert"
)

Expand Down
Loading

0 comments on commit e308e77

Please sign in to comment.