Solana中的投票流程

1. 引言

前序博客有:

2. TPU中收集投票

		let (verified_vote_packets_sender, verified_vote_packets_receiver) = unbounded();
        let cluster_info_vote_listener = ClusterInfoVoteListener::new(
            exit,
            cluster_info.clone(),
            verified_vote_packets_sender,
            poh_recorder,
            vote_tracker,
            bank_forks.clone(),
            subscriptions.clone(),
            verified_vote_sender,
            gossip_verified_vote_hash_sender,
            replay_vote_receiver,
            blockstore.clone(),
            bank_notification_sender,
            cluster_confirmed_slot_sender,
        );

TPU中的监听投票流程与banking_stage是并行进行的。

投票的维度有2种,分别为:

  • vote for label packets
  • vote for transactions
		let (verified_vote_label_packets_sender, verified_vote_label_packets_receiver) =
            unbounded();
        let (verified_vote_transactions_sender, verified_vote_transactions_receiver) = unbounded();

并行处理的流程有:

  • 1)recv_loop():通过gossip协议收集投票信息 -》 验证投票中的交易和label信息-》分别发送transactions vote和label packets vote
let (labels, votes) = cluster_info.get_votes(&mut cursor);
.....
let (vote_txs, packets) = Self::verify_votes(votes, labels);
 verified_vote_transactions_sender.send(vote_txs)?;
verified_vote_label_packets_sender.send(packets)?;
  • 2)bank_send_loop():
    2.1)借助receive_and_process_vote_packets(),若当前Validator为leader,则将相应的packets插入到VerifiedVotePackets中;若不是leader,则清空VerifiedVotePackets。
    2.2)为leader时,借助get_latest_votes(),过滤VerifiedVotePackets中,version版本大于last_version的packets。
    2.3)将过滤后的packets通过verified_packets_sender发出,并更新bank中记录的最新version。
  • 3)process_votes_loop():
    verify_for_unrooted_optimistic_slots():Returns any optimistic slots that were not rooted
    log_unrooted_optimistic_slots()
    progress_leader_schedule_epoch():Update with any newly calculated epoch state about future epochs
    purge_stale_state():Purge any outdated slot data
    listen_and_confirm_votes()
    add_new_optimistic_confirmed_slots():只对confirmed slots进行处理。

3. TVU在replay stage进行投票

4. Tower BFT

【重点看replay_stage,有is_partition_detected().】
Replay_stage::new()->handle_votable_bank->push_vote->generate_vote_tx。
Solana中有维护skipped slot:是指由于leader下线 或 the fork containing the slot was abandoned for a better alternative by cluster consensus 原因,导致的slot中未产块的情况,称为skipped slot。
A skipped slot:
不会作为an ancestor for blocks at subsequent slots
不会increment the block height
决定一个slot是否为skipped slot的标准是:其 becomes older than the latest rooted (thus not-skipped) slot。
root:A block or slot that has reached maximum lockout on a validator. The root is the highest block that is an ancestor of all active forks on a validator. All ancestor blocks of a root are also transitively a root. Blocks that are not an ancestor and not a descendant of the root are excluded from consideration for consensus and can be discarded.
lockout:The duration of time for which a validator is unable to vote on another fork.

	// The number of slots for which this vote is locked
    pub fn lockout(&self) -> u64 {
        (INITIAL_LOCKOUT as u64).pow(self.confirmation_count)
    }

    // The last slot at which a vote is still locked out. Validators should not
    // vote on a slot in another fork which is less than or equal to this slot
    // to avoid having their stake slashed.
    pub fn last_locked_out_slot(&self) -> Slot {
        self.slot + self.lockout()
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值