Commit 22f11ae2 authored by madengji's avatar madengji Committed by vipwzw

config

parent 913fc189
......@@ -43,7 +43,7 @@ enableTxQuickIndex=true
# 升级storedb是否重新执行localdb,bityuan主链升级不需要开启,平行链升级需要开启
enableReExecLocal=true
# 使能精简localdb
enableReduceLocaldb=true
enableReduceLocaldb=false
enablePushSubscribe=false
[p2p]
......@@ -97,7 +97,7 @@ unBindTime=24
#支持挖矿奖励的1e8小数模式,比如18coin 需要配置成1800000000 以支持小数位后的配置,如果true,意味着已经打开即coinReward=1800000000
decimalMode=false
#挖矿模式, 0:普通挖矿,1:减半挖矿,2:自定义
minerMode=2
minerMode=0
#挖矿减半周期,按高度减半
halvePeriod=1000
......
......@@ -165,7 +165,7 @@ func (client *blockSyncClient) batchSyncBlocks() {
}
//没有需要同步的块,清理本地数据库中localCacheCount前的块
if err == nil && curSyncCaughtState {
_, err := client.clearLocalOldBlocks()
err := client.clearLocalOldBlocks()
if err != nil {
client.printError(err)
}
......@@ -289,6 +289,8 @@ func (client *blockSyncClient) delLocalBlocks(startHeight int64, endHeight int64
return errors.New("para sync - startHeight > endHeight,can't clear local blocks")
}
plog.Info("Para sync - clear local blocks", "startHeight:", startHeight, "endHeight:", endHeight)
index := startHeight
set := &types.LocalDBSet{}
cfg := client.paraClient.GetAPI().GetConfig()
......@@ -308,8 +310,6 @@ func (client *blockSyncClient) delLocalBlocks(startHeight int64, endHeight int64
kv := &types.KeyValue{Key: key, Value: types.Encode(&types.Int64{Data: endHeight + 1})}
set.KV = append(set.KV, kv)
client.printDebugInfo("Para sync - clear local blocks", "startHeight:", startHeight, "endHeight:", endHeight)
return client.paraClient.setLocalDb(set)
}
......@@ -356,23 +356,28 @@ func (client *blockSyncClient) getFirstLocalHeight() (int64, error) {
}
//清除指定数量(localCacheCount)以前的区块
func (client *blockSyncClient) clearLocalOldBlocks() (bool, error) {
func (client *blockSyncClient) clearLocalOldBlocks() error {
lastLocalHeight, err := client.paraClient.getLastLocalHeight()
if err != nil {
return false, err
return err
}
firstLocalHeight, err := client.getFirstLocalHeight()
if err != nil {
return false, err
return err
}
canDelCount := lastLocalHeight - firstLocalHeight - client.maxCacheCount + 1
if canDelCount <= client.maxCacheCount {
return false, nil
count := canDelCount / client.maxCacheCount
for i := int64(0); i < count; i++ {
start := firstLocalHeight + i*client.maxCacheCount
end := start + client.maxCacheCount - 1
err = client.delLocalBlocks(start, end)
if err != nil {
return err
}
}
return true, client.delLocalBlocks(firstLocalHeight, firstLocalHeight+canDelCount-1)
return nil
}
// miner tx need all para node create, but not all node has auth account, here just not sign to keep align
......
......@@ -842,6 +842,7 @@ func paraConfigCmd() *cobra.Command {
Short: "parachain config cmd",
}
cmd.AddCommand(paraStageConfigCmd())
cmd.AddCommand(issueCoinsCmd())
return cmd
}
......@@ -1513,3 +1514,45 @@ func GetConsensDoneInfoCmd() *cobra.Command {
addConsensDoneCmdFlags(cmd)
return cmd
}
func issueCoinsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "issue",
Short: "issue new coins by super manager",
Run: createIssueCoinsTx,
}
addIssueCoinsFlags(cmd)
return cmd
}
func addIssueCoinsFlags(cmd *cobra.Command) {
cmd.Flags().Uint64P("amount", "a", 0, "new issue amount")
cmd.MarkFlagRequired("amount")
}
func createIssueCoinsTx(cmd *cobra.Command, args []string) {
paraName, _ := cmd.Flags().GetString("paraName")
coins, _ := cmd.Flags().GetUint64("amount")
if !strings.HasPrefix(paraName, "user.p") {
fmt.Fprintln(os.Stderr, "paraName is not right, paraName format like `user.p.guodun.`")
return
}
if coins == 0 {
fmt.Fprintln(os.Stderr, "coins should bigger than 0")
}
payload := &pt.ParacrossMinerAction{AddIssueCoins: int64(coins)}
params := &rpctypes.CreateTxIn{
Execer: getRealExecName(paraName, pt.ParaX),
ActionName: "Miner",
Payload: types.MustPBToJSON(payload),
}
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
ctx := jsonclient.NewRPCCtx(rpcLaddr, "Chain33.CreateTransaction", params, nil)
ctx.RunWithoutMarshal()
}
......@@ -73,7 +73,7 @@ func (e *Paracross) Exec_CrossAssetTransfer(payload *pt.CrossAssetTransfer, tx *
//Exec_Miner miner tx exec process
func (e *Paracross) Exec_Miner(payload *pt.ParacrossMinerAction, tx *types.Transaction, index int) (*types.Receipt, error) {
if index != 0 {
if index != 0 && payload.AddIssueCoins <= 0 {
return nil, pt.ErrParaMinerBaseIndex
}
cfg := e.GetAPI().GetConfig()
......
......@@ -13,8 +13,14 @@ import (
//当前miner tx不需要校验上一个区块的衔接性,因为tx就是本节点发出,高度,preHash等都在本区块里面的blockchain做了校验
//note: 平行链的Miner从Height=1开始, 创世区块不挖矿
//因为bug原因,支持手动增发一部分coin到执行器地址,这部分coin不会对现有账户产生影响。因为转账到合约下的coin,同时会存到合约子账户下
func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
cfg := a.api.GetConfig()
//增发coin
if miner.AddIssueCoins > 0 {
return a.addIssueCoins(miner.AddIssueCoins)
}
if miner.Status.Title != cfg.GetTitle() || miner.Status.MainBlockHash == nil {
return nil, pt.ErrParaMinerExecErr
}
......@@ -48,6 +54,22 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
return minerReceipt, nil
}
// 主链走None执行器,只在平行链执行,只是平行链的manager 账户允许发行,目前也只是发行到paracross执行器,不会对个人账户任何影响
func (a *action) addIssueCoins(amount int64) (*types.Receipt, error) {
cfg := a.api.GetConfig()
if !isSuperManager(cfg, a.fromaddr) {
return nil, errors.Wrapf(types.ErrNotAllow, "addr=%s,is not super manager", a.fromaddr)
}
issueReceipt, err := a.coinsAccount.ExecIssueCoins(a.execaddr, amount)
if err != nil {
clog.Error("paracross miner issue err", "execAddr", a.execaddr, "amount", amount)
return nil, errors.Wrap(err, "issueCoins")
}
return issueReceipt, nil
}
func (a *action) isSelfConsensOn(miner *pt.ParacrossMinerAction) (bool, error) {
cfg := a.api.GetConfig()
//ForkParaInitMinerHeight高度后,默认全部挖矿,产生在paracross执行器地址,如果自共识分阶段,也只是分阶段奖励,挖矿一直产生
......
......@@ -79,7 +79,8 @@ func TestGetCoins(t *testing.T) {
}
func getCustomRewardMinerRst(miners []string, height int64) (map[string]int64, int64) {
res, change := customRewardMiner(0, miners, height)
c := &custom{}
res, change := c.RewardMiners(0, miners, height)
check := make(map[string]int64)
for _, r := range res {
//fmt.Println("addr",r.Addr,"amount",r.Amount)
......
# 用户定制挖矿奖励方案
## 需求
1. 挖矿数量规则按2^(11-n)计算,随着n增大,奖励减半
1. 比如n=7,奖励是16coin
1. n=8,奖励是8coin
由于新的链5s出一个块,老的链是50s一个块,新的链每一个块的挖矿奖励是原来的1/10
1. n从1开始都有一个自己的高度范围,超出高度范围增1,高度范围算法是40960×(2^n - 1)
1. n=1,高度范围是1~40960, 其中40960*(2^1 -1)=40960就是这个范围的最大高度
1. n=2,高度范围是40961~286720
1. n=6,范围是1269761~2580480
1. n=7,范围是2580481~5201920
如果height=1269880 就可以推导出n来。
由于新的链n从7开始奖励,但是新的链的高度是0,新链的高度偏移是40960*(2^6 -1)
1. 奖励份额分配,三个账户A,B,C,其中A,B分18.75%份额,C分62.5%份额
......@@ -42,24 +42,6 @@ func (a *action) getBindAddrs(nodes []string, statusHeight int64) (*pt.ParaNodeB
}
func rewardEven(coinReward int64, miners []string, height int64) ([]*pt.ParaMinerReward, int64) {
//找零
var change int64
var rewards []*pt.ParaMinerReward
//分配给矿工的平均奖励
minerUnit := coinReward / int64(len(miners))
if minerUnit > 0 {
for _, m := range miners {
r := &pt.ParaMinerReward{Addr: m, Amount: minerUnit}
rewards = append(rewards, r)
}
//如果不等分转到发展基金
change = coinReward % minerUnit
}
return rewards, change
}
func (a *action) rewardSuperNode(coinReward int64, miners []string, statusHeight int64) (*types.Receipt, int64, error) {
cfg := a.api.GetConfig()
receipt := &types.Receipt{Ty: types.ExecOk}
......
......@@ -321,6 +321,7 @@ message ParacrossCommitAction {
message ParacrossMinerAction {
ParacrossNodeStatus status = 1;
bool isSelfConsensus = 2;
int64 addIssueCoins = 3;
}
message ParaMinerReward{
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment