Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
22f11ae2
Commit
22f11ae2
authored
Dec 14, 2020
by
madengji
Committed by
vipwzw
Jan 03, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config
parent
913fc189
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
103 additions
and
32 deletions
+103
-32
chain33.para.toml
chain33.para.toml
+2
-2
parasync.go
plugin/consensus/para/parasync.go
+15
-10
paracross.go
plugin/dapp/paracross/commands/paracross.go
+43
-0
exec.go
plugin/dapp/paracross/executor/exec.go
+1
-1
miner.go
plugin/dapp/paracross/executor/miner.go
+22
-0
minerCustom_test.go
.../dapp/paracross/executor/minerrewards/minerCustom_test.go
+2
-1
minerCustome.md
plugin/dapp/paracross/executor/minerrewards/minerCustome.md
+17
-0
reward.go
plugin/dapp/paracross/executor/reward.go
+0
-18
paracross.proto
plugin/dapp/paracross/proto/paracross.proto
+1
-0
paracross.pb.go
plugin/dapp/paracross/types/paracross.pb.go
+0
-0
No files found.
chain33.para.toml
View file @
22f11ae2
...
@@ -43,7 +43,7 @@ enableTxQuickIndex=true
...
@@ -43,7 +43,7 @@ enableTxQuickIndex=true
# 升级storedb是否重新执行localdb,bityuan主链升级不需要开启,平行链升级需要开启
# 升级storedb是否重新执行localdb,bityuan主链升级不需要开启,平行链升级需要开启
enableReExecLocal
=
true
enableReExecLocal
=
true
# 使能精简localdb
# 使能精简localdb
enableReduceLocaldb
=
tru
e
enableReduceLocaldb
=
fals
e
enablePushSubscribe
=
false
enablePushSubscribe
=
false
[p2p]
[p2p]
...
@@ -97,7 +97,7 @@ unBindTime=24
...
@@ -97,7 +97,7 @@ unBindTime=24
#支持挖矿奖励的1e8小数模式,比如18coin 需要配置成1800000000 以支持小数位后的配置,如果true,意味着已经打开即coinReward=1800000000
#支持挖矿奖励的1e8小数模式,比如18coin 需要配置成1800000000 以支持小数位后的配置,如果true,意味着已经打开即coinReward=1800000000
decimalMode
=
false
decimalMode
=
false
#挖矿模式, 0:普通挖矿,1:减半挖矿,2:自定义
#挖矿模式, 0:普通挖矿,1:减半挖矿,2:自定义
minerMode
=
2
minerMode
=
0
#挖矿减半周期,按高度减半
#挖矿减半周期,按高度减半
halvePeriod
=
1000
halvePeriod
=
1000
...
...
plugin/consensus/para/parasync.go
View file @
22f11ae2
...
@@ -165,7 +165,7 @@ func (client *blockSyncClient) batchSyncBlocks() {
...
@@ -165,7 +165,7 @@ func (client *blockSyncClient) batchSyncBlocks() {
}
}
//没有需要同步的块,清理本地数据库中localCacheCount前的块
//没有需要同步的块,清理本地数据库中localCacheCount前的块
if
err
==
nil
&&
curSyncCaughtState
{
if
err
==
nil
&&
curSyncCaughtState
{
_
,
err
:=
client
.
clearLocalOldBlocks
()
err
:=
client
.
clearLocalOldBlocks
()
if
err
!=
nil
{
if
err
!=
nil
{
client
.
printError
(
err
)
client
.
printError
(
err
)
}
}
...
@@ -289,6 +289,8 @@ func (client *blockSyncClient) delLocalBlocks(startHeight int64, endHeight int64
...
@@ -289,6 +289,8 @@ func (client *blockSyncClient) delLocalBlocks(startHeight int64, endHeight int64
return
errors
.
New
(
"para sync - startHeight > endHeight,can't clear local blocks"
)
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
index
:=
startHeight
set
:=
&
types
.
LocalDBSet
{}
set
:=
&
types
.
LocalDBSet
{}
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
cfg
:=
client
.
paraClient
.
GetAPI
()
.
GetConfig
()
...
@@ -308,8 +310,6 @@ func (client *blockSyncClient) delLocalBlocks(startHeight int64, endHeight int64
...
@@ -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
})}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
&
types
.
Int64
{
Data
:
endHeight
+
1
})}
set
.
KV
=
append
(
set
.
KV
,
kv
)
set
.
KV
=
append
(
set
.
KV
,
kv
)
client
.
printDebugInfo
(
"Para sync - clear local blocks"
,
"startHeight:"
,
startHeight
,
"endHeight:"
,
endHeight
)
return
client
.
paraClient
.
setLocalDb
(
set
)
return
client
.
paraClient
.
setLocalDb
(
set
)
}
}
...
@@ -356,23 +356,28 @@ func (client *blockSyncClient) getFirstLocalHeight() (int64, error) {
...
@@ -356,23 +356,28 @@ func (client *blockSyncClient) getFirstLocalHeight() (int64, error) {
}
}
//清除指定数量(localCacheCount)以前的区块
//清除指定数量(localCacheCount)以前的区块
func
(
client
*
blockSyncClient
)
clearLocalOldBlocks
()
(
bool
,
error
)
{
func
(
client
*
blockSyncClient
)
clearLocalOldBlocks
()
error
{
lastLocalHeight
,
err
:=
client
.
paraClient
.
getLastLocalHeight
()
lastLocalHeight
,
err
:=
client
.
paraClient
.
getLastLocalHeight
()
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
err
}
}
firstLocalHeight
,
err
:=
client
.
getFirstLocalHeight
()
firstLocalHeight
,
err
:=
client
.
getFirstLocalHeight
()
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
err
return
err
}
}
canDelCount
:=
lastLocalHeight
-
firstLocalHeight
-
client
.
maxCacheCount
+
1
canDelCount
:=
lastLocalHeight
-
firstLocalHeight
-
client
.
maxCacheCount
+
1
if
canDelCount
<=
client
.
maxCacheCount
{
count
:=
canDelCount
/
client
.
maxCacheCount
return
false
,
nil
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
nil
return
true
,
client
.
delLocalBlocks
(
firstLocalHeight
,
firstLocalHeight
+
canDelCount
-
1
)
}
}
// miner tx need all para node create, but not all node has auth account, here just not sign to keep align
// miner tx need all para node create, but not all node has auth account, here just not sign to keep align
...
...
plugin/dapp/paracross/commands/paracross.go
View file @
22f11ae2
...
@@ -842,6 +842,7 @@ func paraConfigCmd() *cobra.Command {
...
@@ -842,6 +842,7 @@ func paraConfigCmd() *cobra.Command {
Short
:
"parachain config cmd"
,
Short
:
"parachain config cmd"
,
}
}
cmd
.
AddCommand
(
paraStageConfigCmd
())
cmd
.
AddCommand
(
paraStageConfigCmd
())
cmd
.
AddCommand
(
issueCoinsCmd
())
return
cmd
return
cmd
}
}
...
@@ -1513,3 +1514,45 @@ func GetConsensDoneInfoCmd() *cobra.Command {
...
@@ -1513,3 +1514,45 @@ func GetConsensDoneInfoCmd() *cobra.Command {
addConsensDoneCmdFlags
(
cmd
)
addConsensDoneCmdFlags
(
cmd
)
return
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
()
}
plugin/dapp/paracross/executor/exec.go
View file @
22f11ae2
...
@@ -73,7 +73,7 @@ func (e *Paracross) Exec_CrossAssetTransfer(payload *pt.CrossAssetTransfer, tx *
...
@@ -73,7 +73,7 @@ func (e *Paracross) Exec_CrossAssetTransfer(payload *pt.CrossAssetTransfer, tx *
//Exec_Miner miner tx exec process
//Exec_Miner miner tx exec process
func
(
e
*
Paracross
)
Exec_Miner
(
payload
*
pt
.
ParacrossMinerAction
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
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
return
nil
,
pt
.
ErrParaMinerBaseIndex
}
}
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
cfg
:=
e
.
GetAPI
()
.
GetConfig
()
...
...
plugin/dapp/paracross/executor/miner.go
View file @
22f11ae2
...
@@ -13,8 +13,14 @@ import (
...
@@ -13,8 +13,14 @@ import (
//当前miner tx不需要校验上一个区块的衔接性,因为tx就是本节点发出,高度,preHash等都在本区块里面的blockchain做了校验
//当前miner tx不需要校验上一个区块的衔接性,因为tx就是本节点发出,高度,preHash等都在本区块里面的blockchain做了校验
//note: 平行链的Miner从Height=1开始, 创世区块不挖矿
//note: 平行链的Miner从Height=1开始, 创世区块不挖矿
//因为bug原因,支持手动增发一部分coin到执行器地址,这部分coin不会对现有账户产生影响。因为转账到合约下的coin,同时会存到合约子账户下
func
(
a
*
action
)
Miner
(
miner
*
pt
.
ParacrossMinerAction
)
(
*
types
.
Receipt
,
error
)
{
func
(
a
*
action
)
Miner
(
miner
*
pt
.
ParacrossMinerAction
)
(
*
types
.
Receipt
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
cfg
:=
a
.
api
.
GetConfig
()
//增发coin
if
miner
.
AddIssueCoins
>
0
{
return
a
.
addIssueCoins
(
miner
.
AddIssueCoins
)
}
if
miner
.
Status
.
Title
!=
cfg
.
GetTitle
()
||
miner
.
Status
.
MainBlockHash
==
nil
{
if
miner
.
Status
.
Title
!=
cfg
.
GetTitle
()
||
miner
.
Status
.
MainBlockHash
==
nil
{
return
nil
,
pt
.
ErrParaMinerExecErr
return
nil
,
pt
.
ErrParaMinerExecErr
}
}
...
@@ -48,6 +54,22 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
...
@@ -48,6 +54,22 @@ func (a *action) Miner(miner *pt.ParacrossMinerAction) (*types.Receipt, error) {
return
minerReceipt
,
nil
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
)
{
func
(
a
*
action
)
isSelfConsensOn
(
miner
*
pt
.
ParacrossMinerAction
)
(
bool
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
cfg
:=
a
.
api
.
GetConfig
()
//ForkParaInitMinerHeight高度后,默认全部挖矿,产生在paracross执行器地址,如果自共识分阶段,也只是分阶段奖励,挖矿一直产生
//ForkParaInitMinerHeight高度后,默认全部挖矿,产生在paracross执行器地址,如果自共识分阶段,也只是分阶段奖励,挖矿一直产生
...
...
plugin/dapp/paracross/executor/minerrewards/minerCustom_test.go
View file @
22f11ae2
...
@@ -79,7 +79,8 @@ func TestGetCoins(t *testing.T) {
...
@@ -79,7 +79,8 @@ func TestGetCoins(t *testing.T) {
}
}
func
getCustomRewardMinerRst
(
miners
[]
string
,
height
int64
)
(
map
[
string
]
int64
,
int64
)
{
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
)
check
:=
make
(
map
[
string
]
int64
)
for
_
,
r
:=
range
res
{
for
_
,
r
:=
range
res
{
//fmt.Println("addr",r.Addr,"amount",r.Amount)
//fmt.Println("addr",r.Addr,"amount",r.Amount)
...
...
plugin/dapp/paracross/executor/minerrewards/minerCustome.md
0 → 100644
View file @
22f11ae2
# 用户定制挖矿奖励方案
## 需求
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%份额
plugin/dapp/paracross/executor/reward.go
View file @
22f11ae2
...
@@ -42,24 +42,6 @@ func (a *action) getBindAddrs(nodes []string, statusHeight int64) (*pt.ParaNodeB
...
@@ -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
)
{
func
(
a
*
action
)
rewardSuperNode
(
coinReward
int64
,
miners
[]
string
,
statusHeight
int64
)
(
*
types
.
Receipt
,
int64
,
error
)
{
cfg
:=
a
.
api
.
GetConfig
()
cfg
:=
a
.
api
.
GetConfig
()
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
}
...
...
plugin/dapp/paracross/proto/paracross.proto
View file @
22f11ae2
...
@@ -321,6 +321,7 @@ message ParacrossCommitAction {
...
@@ -321,6 +321,7 @@ message ParacrossCommitAction {
message
ParacrossMinerAction
{
message
ParacrossMinerAction
{
ParacrossNodeStatus
status
=
1
;
ParacrossNodeStatus
status
=
1
;
bool
isSelfConsensus
=
2
;
bool
isSelfConsensus
=
2
;
int64
addIssueCoins
=
3
;
}
}
message
ParaMinerReward
{
message
ParaMinerReward
{
...
...
plugin/dapp/paracross/types/paracross.pb.go
View file @
22f11ae2
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment