Skip to content

Commit

Permalink
feat(bpos): support create aux block with minerInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Oct 21, 2023
1 parent 6cef7cb commit 06a401f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion benchmark/tools/generator/chain/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/tools/generator/chain/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/script/api/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
18 changes: 11 additions & 7 deletions pow/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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()

Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions servers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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"`
Expand All @@ -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"`
Expand Down

0 comments on commit 06a401f

Please sign in to comment.