From 6cef7cb73280decb40ecf4d48501ec14dee6076e Mon Sep 17 00:00:00 2001 From: jiangzehua <1092431698@qq.com> Date: Sat, 21 Oct 2023 15:47:59 +0800 Subject: [PATCH 1/3] feat(auxpow): remove the interval check of CreateAuxBlock --- pow/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pow/service.go b/pow/service.go index 3810b2ca6..81d46a882 100644 --- a/pow/service.go +++ b/pow/service.go @@ -357,7 +357,7 @@ func (pow *Service) CreateAuxBlock(payToAddr string) (*types.Block, error) { defer pow.mutex.Unlock() if pow.chain.GetHeight() == 0 || pow.preChainHeight != pow.chain.GetHeight() || - time.Now().After(pow.preTime.Add(createAuxBlockInterval)) { + time.Now().After(pow.preTime) { if pow.preChainHeight != pow.chain.GetHeight() { // Clear old blocks since they're obsolete now. From 8655913f6bc3f7158e55d4073b45543b1e3729d2 Mon Sep 17 00:00:00 2001 From: jiangzehua <1092431698@qq.com> Date: Sat, 21 Oct 2023 18:01:16 +0800 Subject: [PATCH 2/3] feat(bpos): support create aux block with minerInfo --- benchmark/tools/generator/chain/datagen.go | 2 +- benchmark/tools/generator/chain/utils.go | 2 +- cmd/script/api/block.go | 2 +- docs/jsonrpc_apis.md | 21 ++++++++------------- pow/service.go | 18 +++++++++++------- servers/interfaces.go | 10 +++++++--- 6 files changed, 29 insertions(+), 26 deletions(-) diff --git a/benchmark/tools/generator/chain/datagen.go b/benchmark/tools/generator/chain/datagen.go index 4bf35f69f..e6d5ba5f0 100644 --- a/benchmark/tools/generator/chain/datagen.go +++ b/benchmark/tools/generator/chain/datagen.go @@ -195,7 +195,7 @@ func (g *DataGen) generateBlock( } }) - if block, err = g.pow.GenerateBlock(g.foundationAddr, + if block, err = g.pow.GenerateBlock(g.foundationAddr, "ELA", maxTxPerBlock); err != nil { return } diff --git a/benchmark/tools/generator/chain/utils.go b/benchmark/tools/generator/chain/utils.go index 9a6efa8d2..530386949 100644 --- a/benchmark/tools/generator/chain/utils.go +++ b/benchmark/tools/generator/chain/utils.go @@ -161,7 +161,7 @@ func newGenesisBlock(ac *account.Account) *types.Block { func quickGenerateBlock(pow *pow.Service, prevHash *common.Uint256, txs []interfaces.Transaction, minerAddr string, params *config.Configuration, height uint32) (*types.Block, error) { - coinBaseTx, err := pow.CreateCoinbaseTx(minerAddr, height) + coinBaseTx, err := pow.CreateCoinbaseTx(minerAddr, "ELA", height) if err != nil { return nil, err } diff --git a/cmd/script/api/block.go b/cmd/script/api/block.go index a89d945f8..8ae1c2d79 100644 --- a/cmd/script/api/block.go +++ b/cmd/script/api/block.go @@ -45,7 +45,7 @@ func newBlock(L *lua.LState) int { ChainParams: &config.DefaultParams, TxMemPool: m.Peer.GetTxPool(), }) - block, err := service.GenerateBlock(minerAddress, maxTxPerBlock) + block, err := service.GenerateBlock(minerAddress, service.MinerInfo, maxTxPerBlock) if err != nil { fmt.Printf("New block error: %s \n", err.Error()) } diff --git a/docs/jsonrpc_apis.md b/docs/jsonrpc_apis.md index 1f5f4d12b..feb347c7c 100644 --- a/docs/jsonrpc_apis.md +++ b/docs/jsonrpc_apis.md @@ -918,9 +918,10 @@ Generate an auxiliary block #### Parameter -| name | type | description | -| ------------ | ------ | --------------- | -| paytoaddress | string | miner's address | +| name | type | description | +|--------------| ------ |---------------------| +| paytoaddress | string | miner's address | +| minerinfo | string | miner's information | #### Example @@ -931,16 +932,10 @@ named arguments: ```json { "method":"createauxblock", - "params":{"paytoaddress":"Ef4UcaHwvFrFzzsyVf5YH4JBWgYgUqfTAB"} -} -``` - -positional arguments: - -```json -{ - "method": "createauxblock", - "params": ["Ef4UcaHwvFrFzzsyVf5YH4JBWgYgUqfTAB"] + "params":{ + "paytoaddress":"Ef4UcaHwvFrFzzsyVf5YH4JBWgYgUqfTAB", + "minerinfo": "ELA" + } } ``` diff --git a/pow/service.go b/pow/service.go index 81d46a882..f333ae297 100644 --- a/pow/service.go +++ b/pow/service.go @@ -115,7 +115,8 @@ func (pow *Service) GetDefaultTxVersion(height uint32) common2.TransactionVersio return v } -func (pow *Service) CreateCoinbaseTx(minerAddr string, height uint32) (interfaces.Transaction, error) { +func (pow *Service) CreateCoinbaseTx(minerAddr string, + minerInfo string, height uint32) (interfaces.Transaction, error) { crRewardAddr := pow.chainParams.FoundationProgramHash if height >= pow.chainParams.CRConfiguration.CRCommitteeStartHeight { @@ -135,7 +136,7 @@ func (pow *Service) CreateCoinbaseTx(minerAddr string, height uint32) (interface common2.CoinBase, payload.CoinBaseVersion, &payload.CoinBase{ - Content: []byte(pow.MinerInfo), + Content: []byte(minerInfo), }, []*common2.Attribute{&txAttr}, []*common2.Input{ @@ -255,10 +256,11 @@ func (pow *Service) distributeDPOSReward(coinBaseTx interfaces.Transaction, } func (pow *Service) GenerateBlock(minerAddr string, + minerInfo string, txPerBlock int) (*types.Block, error) { bestChain := pow.chain.BestChain nextBlockHeight := bestChain.Height + 1 - coinBaseTx, err := pow.CreateCoinbaseTx(minerAddr, nextBlockHeight) + coinBaseTx, err := pow.CreateCoinbaseTx(minerAddr, minerInfo, nextBlockHeight) if err != nil { return nil, err } @@ -352,7 +354,7 @@ func (pow *Service) GenerateBlock(minerAddr string, return msgBlock, err } -func (pow *Service) CreateAuxBlock(payToAddr string) (*types.Block, error) { +func (pow *Service) CreateAuxBlock(payToAddr, minerInfo string) (*types.Block, error) { pow.mutex.Lock() defer pow.mutex.Unlock() @@ -366,7 +368,7 @@ func (pow *Service) CreateAuxBlock(payToAddr string) (*types.Block, error) { } // Create new block with nonce = 0 - auxBlock, err := pow.GenerateBlock(payToAddr, maxTxPerBlock) + auxBlock, err := pow.GenerateBlock(payToAddr, minerInfo, maxTxPerBlock) if err != nil { return nil, err } @@ -426,7 +428,8 @@ func (pow *Service) DiscreteMining(n uint32) ([]*common.Uint256, error) { log.Info("<================Discrete Mining==============>\n") for { - msgBlock, err := pow.GenerateBlock(pow.PayToAddr, maxTxPerBlock) + msgBlock, err := pow.GenerateBlock(pow.PayToAddr, + pow.chainParams.PowConfiguration.MinerInfo, maxTxPerBlock) if err != nil { log.Warn("Generate block failed, ", err.Error()) continue @@ -526,7 +529,8 @@ out: log.Debug("<================Packing Block==============>") //time.Sleep(15 * time.Second) - msgBlock, err := pow.GenerateBlock(pow.PayToAddr, maxTxPerBlock) + msgBlock, err := pow.GenerateBlock(pow.PayToAddr, + pow.chainParams.PowConfiguration.MinerInfo, maxTxPerBlock) if err != nil { log.Debug("generage block err", err) continue diff --git a/servers/interfaces.go b/servers/interfaces.go index 4f3354f3d..4b9d5f3d9 100644 --- a/servers/interfaces.go +++ b/servers/interfaces.go @@ -251,8 +251,12 @@ func CreateAuxBlock(param Params) map[string]interface{} { if !ok { return ResponsePack(InvalidParams, "parameter paytoaddress not found") } + minerInfo, ok := param.String("minerinfo") + if !ok { + return ResponsePack(InvalidParams, "parameter minerInfo not found") + } - block, err := Pow.CreateAuxBlock(payToAddr) + block, err := Pow.CreateAuxBlock(payToAddr, minerInfo) if err != nil { return ResponsePack(InternalError, "generate block failed") } @@ -2110,7 +2114,7 @@ type RPCProducerInfo struct { Index uint64 `json:"index"` } -//a group producer info include TotalDPoSV1Votes and producer count +// a group producer info include TotalDPoSV1Votes and producer count type RPCProducersInfo struct { ProducerInfoSlice []RPCProducerInfo `json:"producers"` TotalDPoSV1Votes string `json:"totaldposv1votes"` @@ -2134,7 +2138,7 @@ type RPCCRCandidateInfo struct { Index uint64 `json:"index"` } -//a group cr candidate info include TotalDPoSV1Votes and candidate count +// a group cr candidate info include TotalDPoSV1Votes and candidate count type RPCCRCandidatesInfo struct { CRCandidateInfoSlice []RPCCRCandidateInfo `json:"crcandidatesinfo"` TotalVotes string `json:"totalvotes"` From 5389fb00cb9ea6d9a9cfd584c458ffe8d418be41 Mon Sep 17 00:00:00 2001 From: jiangzehua <1092431698@qq.com> Date: Mon, 23 Oct 2023 17:24:36 +0800 Subject: [PATCH 3/3] feat(bpos): update go version to 1.19 --- .github/workflows/go.yml | 2 +- go.mod | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index a910a5c05..349a0e9ef 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: ["1.16"] + go: ["1.19"] steps: - name: Set up Go ${{ matrix.go }} diff --git a/go.mod b/go.mod index 6a17ab062..9ad4798e4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/elastos/Elastos.ELA -go 1.16 +go 1.19 require ( github.com/RainFallsSilent/screw v1.1.1 @@ -9,7 +9,6 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c github.com/itchyny/base58-go v0.1.0 - github.com/mattn/go-runewidth v0.0.13 // indirect github.com/rs/cors v1.8.0 github.com/spf13/viper v1.12.0 github.com/stretchr/testify v1.7.1 @@ -19,5 +18,40 @@ require ( github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 gopkg.in/cheggaaa/pb.v1 v1.0.28 +) + +require ( + github.com/antlabs/strsim v0.0.2 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/fsnotify/fsnotify v1.5.4 // indirect + github.com/go-echarts/go-echarts/v2 v2.2.3 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.10.1 // indirect + github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/leodido/go-urn v1.2.1 // indirect + github.com/magiconair/properties v1.8.6 // indirect + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml v1.9.5 // indirect + github.com/pelletier/go-toml/v2 v2.0.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rivo/uniseg v0.2.0 // indirect + github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect + github.com/spf13/afero v1.8.2 // indirect + github.com/spf13/cast v1.5.0 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.3.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect + golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect + golang.org/x/text v0.3.7 // indirect + gopkg.in/ini.v1 v1.66.4 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect )