先确认当前的共识参数
state get resource 0x1 0x1::Config::Config<0x1::ConsensusConfig::ConsensusConfig> { "ok": { "json": { "payload": { "base_block_difficulty_window": 24, "base_block_gas_limit": 200000000, "base_block_time_target": 10000, "base_max_uncles_per_block": 2, "base_reward_per_block": 10000000000, "base_reward_per_uncle_percent": 10, "epoch_block_count": 240, "max_block_time_target": 60000, "min_block_time_target": 5000, "strategy": 3, "uncle_rate_target": 100 } }, "raw": "0x6400000000000000102700000000000000e40b540200000000000000000000000a00000000000000f0000000000000001800000000000000881300000000000060ea000000000000020000000000000000c2eb0b0000000003" } }
发起提案交易
这个交易可以以任何账号发起,注意参数顺序,确保不要变更其他不想变更的字段, 可以参考方法:
module OnChainConfig{ public ( script ) fun propose_update_consensus_config(account: signer, uncle_rate_target: u64, base_block_time_target: u64, base_reward_per_block: u128, base_reward_per_uncle_percent: u64, epoch_block_count: u64, base_block_difficulty_window: u64, min_block_time_target: u64, max_block_time_target: u64, base_max_uncles_per_block: u64, base_block_gas_limit: u64, strategy: u8, exec_delay: u64); }
比如下面的提案就只修改了 uncle_rate_target
到 300,max_block_time_target
为 30000
account execute-function -s 0x68b069383b902607f1a9d8c0da7cf539 --function 0x1::OnChainConfigScripts::propose_update_consensus_config --arg 300 --arg 10000 --arg 10000000000u128 --arg 10 --arg 240 --arg 24 --arg 3000 --arg 30000 --arg 2 --arg 200000000 --arg 3u8 --arg 0 -b
交易执行后,再次确认自己提交的提案数据:
state get resource 0x68b069383b902607f1a9d8c0da7cf539 0x1::Dao::Proposal<0x1::STC::STC,0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig>> { "ok": { "json": { "action": { "vec": [ { "value": { "base_block_difficulty_window": 24, "base_block_gas_limit": 200000000, "base_block_time_target": 10000, "base_max_uncles_per_block": 2, "base_reward_per_block": 10000000000, "base_reward_per_uncle_percent": 10, "epoch_block_count": 240, "max_block_time_target": 30000, "min_block_time_target": 3000, "strategy": 3, "uncle_rate_target": 300 } } ] }, "action_delay": 1000, "against_votes": 0, "end_time": 1652933240648, "eta": 0, "for_votes": 0, "id": 43, "proposer": "0x68b069383b902607f1a9d8c0da7cf539", "quorum_votes": 1978801654778413, "start_time": 1652932640648 }, "raw": "0x2b0000000000000068b069383b902607f1a9d8c0da7cf539887f76da8001000048a77fda8001000000000000000000000000000000000000000000000000000000000000000000000000000000000000e8030000000000002dcab6a9b50707000000000000000000012c01000000000000102700000000000000e40b540200000000000000000000000a00000000000000f0000000000000001800000000000000b80b0000000000003075000000000000020000000000000000c2eb0b0000000003" } }
确认提案状态并进行投票
确认提案状态, 第一个参数是发起提案的地址,第二个参数是提案 id ,确认返回值是 2, 如果是 1 说明是在公示阶段,需要等待。如果是 3 说明投票已经过期,需要删除提案,重新发起(测试网的过期时间比较快)。
dev call --function 0x1::Dao::proposal_state -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig> --arg 0x68b069383b902607f1a9d8c0da7cf539 --arg 43 { "ok": [ 2 ] }
可通过以下命令删除提案
account execute-function -s 0x68b069383b902607f1a9d8c0da7cf539 --function 0x1::Dao::destroy_terminated_proposal -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig> --arg 0x68b069383b902607f1a9d8c0da7cf539 --arg 43 -b
通过以下命令确认投票阈值:
dev call --function 0x1::Dao::quorum_votes -t 0x1::STC::STC
通过以下命令进行投票:
account execute-function -s 0x0000000000000000000000000a550c18 --function 0x1::DaoVoteScripts::cast_vote -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig> --arg 0x68b069383b902607f1a9d8c0da7cf539 --arg 44 --arg true --arg 9135020000000000u128 -b
投票完成后等待投票期过, 可以通过以下命令投票时间,返回值的第一个值是 id,第二个值是开始时间,第三个值是结束时间,第四个值是同意的票数,第五个值时反对的票数。
dev call --function 0x1::Dao::proposal_info -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig> --arg 0x68b069383b902607f1a9d8c0da7cf539 { "ok": [ 44, 1652934663057, 1652935263057, 9135020000000000, 0 ] }
等 proposal_state
返回值为 4 的时候,说明投票通过。
放入待执行队列
account execute-function -s 0x68b069383b902607f1a9d8c0da7cf539 --function 0x1::Dao::queue_proposal_action -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig> --arg 0x68b069383b902607f1a9d8c0da7cf539 --arg 44 -b
执行提案
检查提案状态,待执行公示期过后:
account execute-function -s 0x68b069383b902607f1a9d8c0da7cf539 --function 0x1::OnChainConfigScripts::execute_on_chain_config_proposal -t 0x1::ConsensusConfig::ConsensusConfig --arg 44 -b
取回质押 Token
account execute-function -s 0x0000000000000000000000000a550c18 --function 0x1::DaoVoteScripts::unstake_vote -t 0x1::STC::STC -t 0x1::OnChainConfigDao::OnChainConfigUpdate<0x1::ConsensusConfig::ConsensusConfig> --arg 0x68b069383b902607f1a9d8c0da7cf539 --arg 44 -b
投票状态说明
const PENDING: u8 = 1; //等待公示时期 const ACTIVE: u8 = 2; //正在进行投票 const DEFEATED: u8 = 3; //投票期过后,同意的票数小于等于反对的票数,或者同意的票数小于投票阈值,提案被拒绝 const AGREED: u8 = 4; //投票期过后,同意的票数大于反对的票数,提案通过 const QUEUED: u8 = 5; //投票通过的提案被放入等待执行队列进行公示,当前公示期为 24 小时 const EXECUTABLE: u8 = 6; //经过公示期后,进入可执行状态。任何人可以触发执行。 const EXTRACTED: u8 = 7; //提案已经执行