Commit 24b2c046 authored by liuyuhang's avatar liuyuhang Committed by 33cn

add public period configurable

parent b5995cbf
......@@ -38,6 +38,7 @@ func addProposalRuleFlags(cmd *cobra.Command) {
cmd.Flags().Int32P("pubOpposeRatio", "o", 0, "public oppose ratio(unit is %)")
cmd.Flags().Int64P("proposalAmount", "p", 0, "proposal cost amount")
cmd.Flags().Int64P("largeProjectAmount", "l", 0, "large project amount threshold")
cmd.Flags().Int32P("publicPeriod", "u", 0, "public time")
}
func proposalRule(cmd *cobra.Command, args []string) {
......@@ -55,6 +56,7 @@ func proposalRule(cmd *cobra.Command, args []string) {
proposalAmount, _ := cmd.Flags().GetInt64("proposalAmount")
largeProjectAmount, _ := cmd.Flags().GetInt64("largeProjectAmount")
publicPeriod, _ := cmd.Flags().GetInt32("publicPeriod")
params := &auty.ProposalRule{
Year: year,
......@@ -66,6 +68,7 @@ func proposalRule(cmd *cobra.Command, args []string) {
PubOpposeRatio: pubOpposeRatio,
ProposalAmount: proposalAmount * types.Coin,
LargeProjectAmount: largeProjectAmount * types.Coin,
PublicPeriod: publicPeriod,
},
StartBlockHeight: startBlock,
EndBlockHeight: endBlock,
......
......@@ -18,7 +18,7 @@ import (
const (
minBoards = 3
maxBoards = 30
publicPeriod = 120960 // 公示一周时间,以区块高度计算
publicPeriod int32 = 120960 // 公示一周时间,以区块高度计算
ticketPrice = types.Coin * 3000 // 单张票价
largeProjectAmount = types.Coin * 100 *10000 // 重大项目公示金额阈值
proposalAmount = types.Coin * 1000 // 创建者消耗金额
......@@ -374,6 +374,7 @@ func (a *action) getActiveRule() (*auty.RuleConfig, error) {
rule.PubOpposeRatio = pubOpposeRatio
rule.ProposalAmount = proposalAmount
rule.LargeProjectAmount = largeProjectAmount
rule.PublicPeriod = publicPeriod
}
return rule, nil
}
......
......@@ -343,7 +343,7 @@ func (a *action) tmintPropProject(tmintProb *auty.TerminateProposalProject) (*ty
// 公示期间不能终止
if cur.PubVote.Publicity && cur.PubVote.PubPass &&
a.height <= cur.PropProject.RealEndBlockHeight + publicPeriod {
a.height <= cur.PropProject.RealEndBlockHeight + int64(cur.CurRule.PublicPeriod) {
err := auty.ErrTerminatePeriod
alog.Error("tmintPropProject ", "addr", a.fromaddr, "status", cur.Status,
"in publicity vote period can not terminate", tmintProb.ProposalID, "err", err)
......
......@@ -54,6 +54,7 @@ func InitRule(stateDB dbm.KV) {
PubOpposeRatio: pubOpposeRatio,
ProposalAmount: proposalAmount,
LargeProjectAmount: types.Coin *100,
PublicPeriod: publicPeriod,
}
stateDB.Set(activeRuleID(), types.Encode(rule))
}
......
......@@ -16,7 +16,8 @@ import (
func (a *action) propRule(prob *auty.ProposalRule) (*types.Receipt, error) {
//如果全小于等于0,则说明该提案规则参数不正确
if prob.RuleCfg == nil || prob.RuleCfg.BoardAttendRatio <= 0 && prob.RuleCfg.BoardApproveRatio <= 0 &&
prob.RuleCfg.PubOpposeRatio <= 0 && prob.RuleCfg.ProposalAmount <= 0 && prob.RuleCfg.LargeProjectAmount <= 0 {
prob.RuleCfg.PubOpposeRatio <= 0 && prob.RuleCfg.ProposalAmount <= 0 && prob.RuleCfg.LargeProjectAmount <= 0 &&
prob.RuleCfg.PublicPeriod <= 0 {
return nil, types.ErrInvalidParam
}
......@@ -242,7 +243,7 @@ func (a *action) tmintPropRule(tmintProb *auty.TerminateProposalRule) (*types.Re
start := cur.GetPropRule().StartBlockHeight
end := cur.GetPropRule().EndBlockHeight
if a.height <= end && !cur.VoteResult.Pass {
if a.height < end && !cur.VoteResult.Pass {
err := auty.ErrTerminatePeriod
alog.Error("tmintPropRule ", "addr", a.fromaddr, "status", cur.Status, "height", a.height,
"in vote period can not terminate", tmintProb.ProposalID, "err", err)
......@@ -363,6 +364,9 @@ func upgradeRule(cur, modify *auty.RuleConfig) *auty.RuleConfig {
if modify.LargeProjectAmount > 0 {
new.LargeProjectAmount = modify.LargeProjectAmount
}
if modify.PublicPeriod > 0 {
new.PublicPeriod = modify.PublicPeriod
}
return &new
}
......
......@@ -26,6 +26,7 @@ const (
testPubOpposeRatio int32 = 30
testProposalAmount int64 = 0
testLargeProjectAmount int64 = 1
testPublicPeriod int32 = 100
)
func TestRevokeProposalRule(t *testing.T) {
......@@ -63,6 +64,7 @@ func testPropRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB dbm.K
PubOpposeRatio: testPubOpposeRatio,
ProposalAmount: testProposalAmount,
LargeProjectAmount: testLargeProjectAmount,
PublicPeriod:testPublicPeriod,
},
StartBlockHeight: env.blockHeight + 5,
......@@ -163,6 +165,7 @@ func revokeProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB
require.Equal(t, rule.PubOpposeRatio, pubOpposeRatio)
require.Equal(t, rule.ProposalAmount , proposalAmount)
require.Equal(t, rule.LargeProjectAmount, largeProjectAmount)
require.Equal(t, rule.PublicPeriod, publicPeriod)
}
func revokeProposalRuleTx(parm *auty.RevokeProposalRule) (*types.Transaction, error) {
......@@ -285,6 +288,7 @@ func voteProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stateDB d
require.Equal(t, rule.PubOpposeRatio, testPubOpposeRatio)
require.Equal(t, rule.ProposalAmount , proposalAmount)
require.Equal(t, rule.LargeProjectAmount, testLargeProjectAmount)
require.Equal(t, rule.PublicPeriod, testPublicPeriod)
}
func voteProposalRuleTx(parm *auty.VoteProposalRule) (*types.Transaction, error) {
......@@ -362,6 +366,7 @@ func terminateProposalRule(t *testing.T, env *execEnv, exec drivers.Driver, stat
require.Equal(t, rule.PubOpposeRatio, pubOpposeRatio)
require.Equal(t, rule.ProposalAmount , proposalAmount)
require.Equal(t, rule.LargeProjectAmount, largeProjectAmount)
require.Equal(t, rule.PublicPeriod, publicPeriod)
}
func terminateProposalRuleTx(parm *auty.TerminateProposalRule) (*types.Transaction, error) {
......@@ -433,6 +438,7 @@ func TestUpgradeRule(t *testing.T) {
PubOpposeRatio: 3,
ProposalAmount: 4,
LargeProjectAmount: 5,
PublicPeriod: 6,
}
modify := &auty.RuleConfig{
BoardAttendRatio: 0,
......@@ -440,6 +446,7 @@ func TestUpgradeRule(t *testing.T) {
PubOpposeRatio: 0,
ProposalAmount: -1,
LargeProjectAmount: 0,
PublicPeriod: 0,
}
new = upgradeRule(cur, modify)
require.NotNil(t, new)
......@@ -448,6 +455,7 @@ func TestUpgradeRule(t *testing.T) {
require.Equal(t, new.PubOpposeRatio, cur.PubOpposeRatio)
require.Equal(t, new.ProposalAmount , cur.ProposalAmount)
require.Equal(t, new.LargeProjectAmount, cur.LargeProjectAmount)
require.Equal(t, new.PublicPeriod, cur.PublicPeriod)
modify = &auty.RuleConfig{
BoardAttendRatio: 10,
......@@ -455,6 +463,7 @@ func TestUpgradeRule(t *testing.T) {
PubOpposeRatio: 30,
ProposalAmount: 40,
LargeProjectAmount: 50,
PublicPeriod: 60,
}
new = upgradeRule(cur, modify)
require.NotNil(t, new)
......@@ -463,4 +472,5 @@ func TestUpgradeRule(t *testing.T) {
require.Equal(t, new.PubOpposeRatio, modify.PubOpposeRatio)
require.Equal(t, new.ProposalAmount , modify.ProposalAmount)
require.Equal(t, new.LargeProjectAmount, modify.LargeProjectAmount)
require.Equal(t, new.PublicPeriod, modify.PublicPeriod)
}
\ No newline at end of file
......@@ -43,4 +43,6 @@ message RuleConfig {
int64 proposalAmount = 4;
// 重大项目公示金额阈值
int64 largeProjectAmount = 5;
// 重大项目公示时间(以区块数为单位)
int32 publicPeriod = 6;
}
\ No newline at end of file
......@@ -127,6 +127,8 @@ type RuleConfig struct {
ProposalAmount int64 `protobuf:"varint,4,opt,name=proposalAmount" json:"proposalAmount,omitempty"`
// 重大项目公示金额阈值
LargeProjectAmount int64 `protobuf:"varint,5,opt,name=largeProjectAmount" json:"largeProjectAmount,omitempty"`
// 重大项目公示时间(以区块数为单位)
PublicPeriod int32 `protobuf:"varint,6,opt,name=publicPeriod" json:"publicPeriod,omitempty"`
}
func (m *RuleConfig) Reset() { *m = RuleConfig{} }
......@@ -169,6 +171,13 @@ func (m *RuleConfig) GetLargeProjectAmount() int64 {
return 0
}
func (m *RuleConfig) GetPublicPeriod() int32 {
if m != nil {
return m.PublicPeriod
}
return 0
}
func init() {
proto.RegisterType((*VoteResult)(nil), "types.VoteResult")
proto.RegisterType((*PublicVote)(nil), "types.PublicVote")
......@@ -179,24 +188,25 @@ func init() {
func init() { proto.RegisterFile("lcommon.proto", fileDescriptor2) }
var fileDescriptor2 = []byte{
// 299 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xcd, 0x4a, 0xc3, 0x40,
0x10, 0x80, 0x49, 0x7f, 0xb4, 0x9d, 0xaa, 0xe8, 0x9c, 0x7a, 0x10, 0x29, 0x39, 0x68, 0x11, 0xe9,
0xc5, 0x27, 0x28, 0x3e, 0x80, 0x65, 0x0f, 0xde, 0x37, 0xc9, 0x5a, 0x22, 0xdb, 0xcc, 0xb2, 0x3b,
0x2b, 0xf4, 0x05, 0x7c, 0x54, 0x9f, 0x43, 0x32, 0xdb, 0xd2, 0xda, 0x08, 0xde, 0x32, 0xdf, 0x7e,
0x87, 0x6f, 0x86, 0xc0, 0xa5, 0x2d, 0x69, 0xb3, 0xa1, 0x66, 0xe1, 0x3c, 0x31, 0xe1, 0x90, 0xb7,
0xce, 0x84, 0xfc, 0x2b, 0x03, 0x78, 0x23, 0x36, 0xca, 0x84, 0x68, 0x19, 0xef, 0x00, 0x98, 0x58,
0xdb, 0x16, 0x85, 0x69, 0x36, 0xcb, 0xe6, 0x43, 0x75, 0x44, 0x30, 0x87, 0x0b, 0xed, 0x9c, 0xa7,
0x4f, 0x93, 0x8c, 0x9e, 0x18, 0xbf, 0x18, 0xce, 0x60, 0x42, 0xce, 0x51, 0xd8, 0x29, 0x7d, 0x51,
0x8e, 0x11, 0x22, 0x0c, 0x9c, 0x0e, 0x61, 0x3a, 0x98, 0x65, 0xf3, 0x91, 0x92, 0x6f, 0x09, 0x59,
0xc5, 0xc2, 0xd6, 0x65, 0xeb, 0xe0, 0x2d, 0x8c, 0x9d, 0x4c, 0x35, 0x6f, 0xa5, 0x63, 0xa4, 0x0e,
0xe0, 0x24, 0xb3, 0xd7, 0xc9, 0xfc, 0x3f, 0x61, 0x0a, 0xe7, 0x2e, 0x16, 0xab, 0x43, 0xc5, 0x7e,
0xcc, 0x1f, 0x60, 0x22, 0x8a, 0x32, 0x25, 0xf9, 0xaa, 0x15, 0x75, 0x55, 0x79, 0x13, 0xda, 0x73,
0xf4, 0xe7, 0x63, 0xb5, 0x1f, 0xf3, 0xef, 0x0c, 0x40, 0x45, 0x6b, 0x5e, 0xa8, 0x79, 0xaf, 0xd7,
0xf8, 0x08, 0xd7, 0x05, 0x69, 0x5f, 0x2d, 0x99, 0x4d, 0x53, 0x29, 0xcd, 0x35, 0xed, 0x0e, 0xd8,
0xe1, 0xf8, 0x04, 0x37, 0x89, 0xa5, 0xbb, 0x25, 0x39, 0xad, 0xd1, 0x7d, 0xc0, 0x7b, 0xb8, 0x72,
0xb1, 0x78, 0x95, 0xfa, 0xa4, 0xa6, 0x85, 0x4e, 0xa8, 0x78, 0x9e, 0x1c, 0x05, 0x6d, 0x97, 0x1b,
0x8a, 0x0d, 0xcb, 0x6a, 0x7d, 0x75, 0x42, 0x71, 0x01, 0x68, 0xb5, 0x5f, 0x9b, 0x95, 0xa7, 0x0f,
0x53, 0xf2, 0xce, 0x1d, 0x8a, 0xfb, 0xc7, 0x4b, 0x71, 0x26, 0x7f, 0xcc, 0xf3, 0x4f, 0x00, 0x00,
0x00, 0xff, 0xff, 0x39, 0xcc, 0x0c, 0x6d, 0x42, 0x02, 0x00, 0x00,
// 314 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0x3d, 0x4e, 0xf3, 0x40,
0x10, 0x86, 0xe5, 0xfc, 0x7d, 0xc9, 0xe4, 0x03, 0xc1, 0x54, 0x2e, 0x10, 0x8a, 0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be, 0x5a, 0x33, 0x9b, 0xa6, 0x52, 0x9a, 0x6b, 0xda,
0x17, 0xd8, 0xe3, 0xf8, 0x08, 0xd7, 0x91, 0xc5, 0xde, 0xa2, 0x1c, 0xd7, 0xe8, 0x3f, 0xe0, 0x1d,
0x5c, 0xba, 0xb6, 0x78, 0x91, 0xf4, 0x51, 0x8d, 0x0b, 0x9d, 0x51, 0xf1, 0x3c, 0x39, 0x0a, 0xda,
0xae, 0xb7, 0xd4, 0x36, 0x2c, 0xab, 0x0d, 0xd5, 0x19, 0xc5, 0x15, 0xa0, 0xd5, 0x7e, 0x63, 0x72,
0x4f, 0xef, 0xa6, 0xe4, 0xbd, 0x3b, 0x16, 0xf7, 0x97, 0x97, 0xee, 0xe8, 0xb1, 0xfa, 0xdc, 0xf8,
0x9a, 0xaa, 0x74, 0x12, 0x8f, 0x7e, 0xca, 0x8a, 0x89, 0xfc, 0x55, 0x4f, 0xdf, 0x01, 0x00, 0x00,
0xff, 0xff, 0x26, 0x63, 0x46, 0xa7, 0x66, 0x02, 0x00, 0x00,
}
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