EOS鍏辫瘑鎬荤粨
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EOS鍏辫瘑鎬荤粨相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/gen' title='gen'>gen 璁$畻杩囩▼ existing 鍥剧墖 res second tin status art
1 鍩烘湰姒傚康1 eos 姣?00姣鍑轰竴涓潡锛屾瘡涓敓浜ц妭鐐硅繛缁嚭12涓潡锛岀劧鍚庡垏鎹㈠埌涓嬩竴鑺傜偣鐢熶骇銆?/p>
2 eos闇€瑕佷袱杞叡璇?/p>
銆€銆€鏂扮敓浜?鎺ユ敹鐨勫潡浼氭斁鍏ュ唴瀛樺潡鍒嗗弶鏁版嵁搴揻ork_db涓紝绛夊緟鍏辫瘑銆?/p>
? 鍗曡妭鐐逛笉鍙€嗗潡锛氭垜浠妸瀹屾垚绗竴杞叡璇嗙殑鍧楋紝鍙仛鍗曡妭鐐逛笉鍙€嗗潡銆?/p>
銆€銆€鍏ㄧ綉涓嶅彲閫嗗潡锛氥€€瀹屾垚绗簩杞叡璇嗙殑鍧楋紝鍙叏缃戜笉鍙€嗗潡銆?/p>
銆€銆€瀹屾垚涓よ疆鍏辫瘑鐨勫叏缃戜笉鍙€嗗潡锛屾墠鏄垜浠父璇寸殑鐪熸鎰忎箟涓婄殑涓嶅彲閫嗗潡锛屼細浠巉ork_db涓Щ鍑哄啓鍏lock_log锛屽疄鐜拌惤鍧椼€?/p>
3 鍏辫瘑鐩稿叧鍏抽敭鍙橀噺
? 涓嬮潰鏄痚os涓畾涔夌殑block_header_state鏁版嵁缁撴瀯锛屽叡璇嗙敤鍒扮殑澶у鏁板彉閲忓€奸兘淇濆瓨鍦ㄨ繖閲岋細
```c++
struct block_header_state
uint32_t block_num = 0;//鍧楀彿
// 1 绗竴杞? , 璁板綍姣忎釜鍧楃殑寰呯‘璁ゆ暟锛? vector<uint8_t> confirm_count; // [1,1,1,...2,2,2,...3,3,3]
// 2 绗簩杞紝 缁忚繃棣栬疆纭锛屽緱鍒扮殑鍊欓€変笉鍙€嗭紝鍗曡妭鐐逛笉鍙€嗘渶澶у潡鍙? uint32_t dpos_proposed_irreversible_blocknum = 0;
// 璁板綍姣忎釜鐢熶骇鑰呯殑鏈€鍚庝笉鍙€嗗潡搴忓彿
flat_map<account_name,uint32_t> producer_to_last_implied_irb;
// 3 鍏ㄧ綉涓嶅彲閫嗗潡鍙? uint32_t dpos_irreversible_blocknum = 0;
//1 绗竴杞? ,姘村嵃鍊硷紝璁板綍姣忎釜鐢熶骇鑰呯敓浜х殑鏈€鍚庝竴涓潡鐨勫潡鍙枫€?br/>std::map<chain::account_name, uint32_t> _producer_watermarks;
* confirm_count锛歷ector鏁扮粍锛岀涓€杞叡璇嗕娇鐢紝閲岄潰淇濆瓨鐫€鏈畬鎴愮涓€杞叡璇嗙殑鍧楃殑寰呯‘璁ゆ暟銆?
* dpos_proposed_irreversible_blocknum 锛氬崟鑺傜偣涓嶅彲閫嗗潡鍙凤紝绗簩杞叡璇嗕娇鐢紝璁板綍缁忚繃绗竴杞叡璇嗗緱鍒扮殑鍗曡妭鐐逛笉鍙€嗗潡鍙枫€?
* producer_to_last_implied_irb锛歮ap瀵硅薄锛屽瓨鏀剧敓浜ц€呭強鍗曡妭鐐逛笉鍙€嗗潡鍙风殑閿€煎锛岀浜岃疆鍏辫瘑鐢ㄣ€?
* dpos_irreversible_blocknum锛氬畬鎴愮浜岃疆鍏辫瘑鐨勬渶鏂板叏缃戜笉鍙€嗗潡鍧楀彿锛屾牴鎹鍧楀彿瀹炵幇钀藉潡銆?
鍙﹀鐢熶骇鑰呮按鍗板€间篃鏄竴涓敤浜庡叡璇嗙殑鍏抽敭鍙橀噺鍊硷紝淇濆瓨鍦ㄧ敓浜ц€呮彃浠朵腑锛?
```c++
//1 绗竴杞? 鐢熶骇鑰呮按鍗板€硷紝璁板綍姣忎釜鐢熶骇鑰呯敓浜х殑鏈€鍚庝竴涓潡鐨勫潡鍙枫€? std::map<chain::account_name, uint32_t> _producer_watermarks;
- _producer_watermarks: map瀵硅薄锛岀敓浜ц妭鐐规按鍗板€硷紝绗竴杞叡璇嗕娇鐢紝淇濆瓨姣忎釜鐢熶骇鑺傜偣鏈€鍚庣敓浜х殑鍧楀彿銆?/li>
2 鍏辫瘑鍘熺悊涓句緥
绗竴杞叡璇?/p>
-
鐢熶骇鑺傜偣浼氬瀹冩湭纭鐨勫潡杩涜纭鍏辫瘑锛屾湭纭鍧楁暟=褰撳墠閾惧ご鍧楀彿-瀹冩渶鍚庡嚭鍧楃殑鍧楀彿銆?/p>
- 鑺傜偣鍑哄潡鏃讹紝浼氭寜鎷滃崰搴皢鍐涚畻娉?褰撳墠鐢熶骇鑺傜偣鏁?2/3+1)璁$畻璇ュ潡闇€瑕佸嚑涓妭鐐瑰叡璇嗭紝骞舵妸璇ュ€兼斁鍏ュ緟鍏辫瘑鏁扮粍confirm_count[]鐨勬渶鍚庛€?/li>
-
鐢熶骇鑺傜偣鍑哄潡鏃讹紝闄や簡浼氬叡璇嗕箣鍓嶆湭纭杩囩殑鍧楋紝涔熶細瀵规湰娆″嚭鐨勫潡杩涜鏈妭鐐圭‘璁ゅ叡璇嗐€?/p>
-
鍙湁鐢熶骇鑺傜偣鍑哄潡鏃讹紝鎵嶄細瀵逛箣鍓嶈妭鐐瑰嚭鐨勫潡杩涜纭鍏辫瘑锛岃妭鐐规敹鍒板潡鏃讹紝骞朵笉鍋氬鏀跺埌鐨勫潡杩涜纭鍏辫瘑銆?/p>
浠?涓敓浜ц妭鐐规瘡杞嚭2涓潡涓轰緥锛屽亣璁炬鏃惰疆鍒拌妭鐐?鍑虹7鍧楋細
1 璁$畻鑺傜偣1鏈‘璁ゅ潡鏁帮細鐩墠閾惧ご鍧楀潡鍙? - 鑺傜偣姘村嵃鍊?锛堣妭鐐?鐢熶骇鐨勬渶鍚庝竴涓潡锛?4锛?/p>
? 鍗崇敓浜?鍙峰潡鏃讹紝鍓嶉潰鏈?涓潡寰呰妭鐐?纭銆?/p>
2 璁$畻7鍙峰潡闇€瑕佽鍑犱釜鑺傜偣纭锛? 3锛堣妭鐐规暟)* 2/3 +1 = 3锛屽皢3鏀惧叆confirm_count[]鏈€鍚庯紱
3 绗竴杞叡璇嗚绠楋細瀹為檯灏辨槸瀵筩onfirm_count[]鏁扮粍涓繚瀛樼殑寰呯‘璁ゆ暟杩涜鍑?璁$畻銆?/p>
? 鍧楀緟纭鏁扮粍confirm_count[] 鍦ㄧ涓€杞叡璇嗕腑鐨勫彉鍔ㄦ儏鍐靛睍绀哄涓嬶細
- 鐢熶骇7鍧楀墠锛岄噷闈㈡湁4涓緟纭鍧椼€?/li>
- 鍏堝皢7鍧楃殑寰呯‘璁ゆ暟3鎻抍onfirm_count鐨勬渶鍚庛€?/li>
- 寰幆浠巆onfirm_count[]灏鹃儴瀵瑰叾涓殑鍊兼墽琛屽噺1鎿嶄綔銆傚綋鏈塩onfirm_count[i]==0鎴愮珛锛屽仠姝㈠惊鐜€俰浣嶇疆瀵瑰簲鐨勫潡鍙凤紝鍗虫娆″叡璇嗗緱鍒扮殑鍗曡妭鐐逛笉鍙€嗗潡鍙凤紝姝ゆ椂4鍙峰潡鎴愪负鍗曡妭鐐逛笉鍙€嗗潡锛屽畠涔嬪墠鐨勫潡涓嶇敤璁$畻锛岄兘鑷姩鎴愪负鍗曡妭鐐逛笉鍙€嗗潡銆?/li>
- 绉诲姩confirm_count[],娓呴櫎4鍙峰潡涔嬪墠鎵€鏈夊潡銆?/li>
绗竴杞叡璇嗗畬鎴?寰楀埌dpos_proposed_irreversible_blocknum=4銆?/p>
绗簩杞叡璇?/p>
? 杩欓噷涓昏鐢ㄥ埌producer_to_last_implied_irb锛屽畠鏄竴涓猰ap瀹瑰櫒锛岄噷闈㈡斁鐨勬槸鐢熶骇鑺傜偣鐨勮妭鐐瑰悕鍙婅鑺傜偣瀵瑰簲鐨勫崟鐐逛笉鍙€嗗潡鍙凤紝姝ゅ鐨勫崟鐐逛笉鍙€嗗潡鍙峰氨鏄鑺傜偣鍦ㄦ墽琛岀涓€杞叡璇嗚绠楁椂寰楀埌鐨勫€笺€傚彧鏈夊嚭鍧楄妭鐐圭殑鍗曡妭鍗曡妭鐐逛笉鍙€嗗€兼墠浼氭洿鏂般€?/p>
鍒氭墠鐢熶骇7鍙峰潡鏃惰绠楀緱鍒拌妭鐐?鐨勫綋鍓嶄笉鍙€嗗潡鍙锋槸4锛屽彲鎺ㄥ緱姝ゆ椂鑺傜偣3瀵瑰簲鐨勫€煎簲璇ユ槸2锛岃妭鐐?瀵瑰簲鍊?銆傚綋鑺傜偣2鐢熶骇绗?涓潡鏃讹紝鑺傜偣2绗竴杞叡璇嗗緱鍒扮殑鍗曡妭鐐逛笉鍙€嗗潡鍙?锛?鍏跺畠鑺傜偣涓嶅彉锛屽涓嬪浘鎵€绀猴細
eos鐨勭浜岃疆鍏辫瘑绠楁硶锛屼細灏唒roducer_to_last_implied_irb涓殑鍧楀彿鎺掑簭锛屼粠灏忓埌澶у彇1/3浣嶇疆鐨勫潡锛屾垚涓烘渶缁堜笉鍙€嗗潡銆?/p>
-
7 鍙峰潡鐢熶骇鏃讹紝鍙栨渶灏?/3鐨勫潡锛屽潡鍙蜂负0锛屾鏃舵病鏈夊潡鎴愪负鍏ㄧ綉涓嶅彲閫嗗潡銆?/p>
-
9鍙峰潡鐢熶骇鏃讹紝鍙栨渶灏?/3鐨勫潡锛屽潡鍙蜂负2锛屾鏃?鍙蜂箣鍓嶇殑鍧楅兘鎴愪负鍏ㄧ綉涓嶅彲閫嗗潡銆?/p>
绗簩杞叡璇嗙粨鏉燂紝7鍙峰潡鐢熶骇鏃讹紝鍏ㄧ綉涓嶅彲閫嗗潡dpos_irreversible_blocknum = 0锛?/p>
9鍙峰潡鐢熶骇鏃讹紝鍏ㄧ綉涓嶅彲閫嗗潡dpos_irreversible_blocknum = 2锛?/p>
3 eos鍧楀叡璇嗘祦绋?/h3>
? 涓嬪浘涓烘牴鎹甧os鍧楃敓浜ф祦绋嬬敾鍑虹殑鍧楀叡璇嗘祦绋嬶紝涓嬮潰鍒嗗埆浠庣敓浜ц妭鐐逛綔涓虹敓浜ц€呭嚭鍧楀拰浣滀负楠岃瘉鑺傜偣鏀跺埌涓ょ鎯呭喌锛岀粨鍚堜唬鐮佸垎鍒涓よ疆鍏辫瘑娴佺▼灞曞紑杩涜鍒嗘瀽銆?/p>
? 鑺傜偣浣滀负楠岃瘉鑺傜偣鏀跺埌鍧楋紝浼氳皟鐢╟onntroller_impl::apply_block锛堬級鍑芥暟锛屽鐞嗗潡涓暟鎹紝鏈€缁堣惤鍧椼€傚浘涓孩鑹插簳妗嗙殑鍐呭鏄涓€杞叡璇嗙敤鍒扮殑鍑芥暟鎴栧彉閲忥紝姗欒壊搴曟鍒欐槸绗簩杞叡璇嗙敤鍒扮殑銆?/p>
3.1 鍑哄潡鑺傜偣鍏辫瘑
3.1.1 绗竴杞叡璇?/h5>
? 鑺傜偣寰幆璋冪敤schedule_production_loop锛堬級鍑芥暟杩涜鐢熶骇寰幆锛屽嚱鏁颁腑浼氳皟鐢╯tart_block()鍒ゆ柇鏄惁璇ユ湰鑺傜偣鍑哄潡銆?/p>
- 璁$畻鏈潡闇€瑕佺‘璁ょ殑鍧楁暟锛歜locks_to_confirm = 閾惧ご鍧楀彿 - 鏈妭鐐规按鍗板€硷紱
```c++
producer_plugin_impl::start_block_result producer_plugin_impl::start_block()
//璁$畻鍑哄潡鑰?br/>const auto& scheduled_producer = hbs->get_scheduled_producer(block_time);
//鑾峰彇璇ュ嚭鍧楄€呭凡鍑烘渶鍚庝竴涓潡鐨勫潡鍙?br/>auto currrent_watermark_itr =
_producer_watermarks.find(scheduled_producer.producer_name);
if (currrent_watermark_itr != _producer_watermarks.end())
//姘村嵃鍊?鑺傜偣鐢熶骇鐨勬渶鍚庡潡鍙?
auto watermark = currrent_watermark_itr->second;
if (watermark < hbs->block_num)
//寰呯‘璁ゅ潡鏁?閾惧ご鍧楀彿-鏈妭鐐规渶鍚庣敓浜х殑鍧楀彿
blocks_to_confirm = hbs->block_num - watermark;
...
chain.start_block(block_time, blocks_to_confirm);
?
2. 杞埌鏈妭鐐瑰嚭鍧楋紝灏嗗嚭鍧楁椂闂村拰blocks_to_confirm浣滀负鍙傛暟浼犲叆controller_impl::start_block()鍑芥暟锛屽惎鍔ㄥ嚭鍧楋細
```c++
void start_block(block_timestamp_type when, uint16_t confirm_block_count,.. )
...
//鏋勯€燽lock_state绫诲瀷
pending->_pending_block_state = std::make_shared<block_state>( *head, when );
...
// 鎵ц绗竴杞叡璇?
pending->_pending_block_state->set_confirmed(confirm_block_count);
//鐢熶骇鑰呭垏鎹? auto was_pending_promoted =
pending->_pending_block_state->maybe_promote_pending();
...
-
棣栧厛鏋勯€燽lock_state鏁版嵁锛屽瓨鍧楃殑鏁版嵁淇℃伅锛宐lock_state鏄痓lock_header_state鐨勫瓙绫伙紝鏋勯€犳椂浼氬厛璋冪敤block_header_state::generate_next锛堬級鍑芥暟锛屾瀯閫燽lock_header_state锛?br/>```c++
block_header_state::generate_next( block_timestamp_type when )constblock_header_state result;
//鏍规嵁鐢熶骇鑰呮暟閲忚绠楃敓浜у潡鐨勫緟纭鏁皉equired_confs
auto num_active_producers = active_schedule.producers.size();
uint32_t required_confs = (uint32_t)(num_active_producers * 2 / 3) + 1;
...
//required_confs鎻掑叆confirm_count[]鏈€鍚?br/>result.confirm_count.back() = (uint8_t)required_confs;//producer_to_last_implied_irb鏁扮粍鏋勫缓
result.dpos_proposed_irreversible_blocknum =
dpos_proposed_irreversible_blocknum;
result.producer_to_last_implied_irb[prokey.producer_name] =
result.dpos_proposed_irreversible_blocknum;//绗簩杞‘璁わ紝浠庡缓璁笉鍙€嗗潡鏁扮粍璁$畻鏈€缁堜笉鍙€嗗潡鍙枫€?br/>result.dpos_irreversible_blocknum = result.calc_dpos_last_irreversible();
- 璁$畻鏈鍑哄潡鐨勫緟纭鏁帮紝鏀惧叆寰呯‘璁ゆ暟缁刢onfirm_count[]鐨勬渶鍚庛€?
- 鏇存柊producer_to_last_implied_irb涓湰鑺傜偣鐨勫崟鑺傜偣涓嶅彲閫嗗潡鍙枫€?/li>
- 鏍规嵁producer_to_last_implied_irb鐨勫€艰繘琛岀浜岃疆鍏辫瘑璁$畻锛屽叿浣撶畻娉曞悗闈㈠垎鏋愩€?/li>
generate_next()涓凡灏嗘湰娆$敓浜у潡鐨勫緟纭鏁板姞鍏ヤ簡confirm_count[]涓紝涓嬮潰寮€濮嬬涓€杞叡璇嗚绠楋細
```c++
void block_header_state::set_confirmed( uint16_t num_prev_blocks )
//confirm_count[] [1,1,1,...2,2,2,...3,3,3] 璁板綍鎵€鏈夊緟纭鍧?br/>int32_t i = (int32_t)(confirm_count.size() - 1);
// 鏈纭鍧楁暟锛屼紶鍏ョ‘璁ゆ暟+1 鎶婃湰娆″嚭鐨勫潡涔熺‘璁や簡
uint32_t blocks_to_confirm = num_prev_blocks + 1;
//浠巆onfirm_count鏈€鍚庢斁鍏ョ殑鏈€鏂板潡寮€濮嬬‘璁わ紝閫愪釜鍑忎竴
while( i >= 0 && blocks_to_confirm )
--confirm_count[i];
//鍑忓畬鍚?=0锛岃鍧楄纭娆℃暟婊¤冻璇ュ潡璁惧畾鐨勫緟纭鏁? if( confirm_count[i] == 0 )
//璁$畻鍧楀彿
uint32_t block_num_for_i = block_num - (uint32_t)(confirm_count.size() - 1 - i);
//寤鸿涓嶅彲閫嗗潡鍙疯涓鸿鍧楀彿
dpos_proposed_irreversible_blocknum = block_num_for_i;
//璇ュ潡灏辨槸confirm_count鏈€鍚庝竴涓紝confirm_count閲嶇疆
if (i == confirm_count.size() - 1)
confirm_count.resize(0);
else
//璇ュ潡涔嬪墠鐨勮褰曢兘娓呴櫎
memmove( &confirm_count[0], &confirm_count[i + 1], confirm_count.size() - i - 1);
confirm_count.resize( confirm_count.size() - i - 1 );
return;
--i;
--blocks_to_confirm;
* 鍙傛暟num_prev_blocks鏄摼澶村潡鍙峰噺姘村嵃鍊煎緱鍒扮殑锛屽洜涓哄鏈鐢熶骇鐨勫潡涔熻杩涜纭锛屾墍浠ワ紝瀹為檯纭鍧楁暟浼氬姞1銆?* 浠庡悗鍒板墠瀵筩onfirm_count[]鍑?锛岀浉褰撲簬鑺傜偣纭浜嗚鍧椼€?* 绗竴涓娇confirm_count[i]==0鎴愮珛澶勭殑鍧楀彿锛屽氨鏄粡杩囩涓€杞叡璇嗗緱鍒扮殑鍗曡妭鐐逛笉鍙€嗗潡鍙枫€?
鍑哄潡鏃堕棿鍒帮紝鑺傜偣浼氳皟鐢╬roduce_block()鍑芥暟杩涜涓€浜涙敹灏惧伐浣滐紝姣斿璁$畻榛樺厠灏旀牴锛屽潡绛惧悕绛夛紝鐢熶骇鑰呮按鍗板€间篃鏄湪杩欓噷璺熸柊鐨勶細
```c++
void producer_plugin_impl::produce_block()
...
chain.finalize_block();
chain.commit_block();
...
//璁板綍鐢熶骇鑰呮按鍗板€硷紝璁板綍褰撳墠鐢熶骇鑰呯敓浜х殑鏈€鏂板潡鍧楀彿
_producer_watermarks[new_bs->header.producer] = chain.head_block_num();
- chain.commit_block()鍑芥暟涓細灏嗘娆$敓浜х殑鍧楀姞鍏ork_db搴撲腑锛屼笖灏嗛摼澶村潡璺熸柊涓烘娆$敓浜х殑鍧椼€?/li>
- chain.head_block_num()鍑芥暟浼氬緱鍒板綋鍓嶉摼澶村潡鍧楀彿銆?/li>
3.1.2 绗簩杞叡璇?/h5>
鍓嶉潰宸茬粡浠嬬粛浜嗭紝鍦╣enerate_next()涓細璋冪敤calc_dpos_last_irreversible()鍑芥暟杩涜绗簩杞叡璇嗚绠楋紝涓嬮潰鎴戞潵鐪嬩竴涓嬪叿浣撶殑璁$畻杩囩▼锛?br/>```c++
uint32_t block_header_state::calc_dpos_last_irreversible()const
vector<uint32_t> blocknums;
blocknums.reserve( producer_to_last_implied_irb.size() );
for( auto& i : producer_to_last_implied_irb )
blocknums.push_back(i.second);
if( blocknums.size() == 0 ) return 0;
std::sort( blocknums.begin(), blocknums.end() );
return blocknums[ (blocknums.size()-1) / 3 ];
锛娿€€ new_producer_to_last_implied_irb 鏄竴涓猰ap瀹瑰櫒缁撴瀯锛岄噷闈㈡斁鐨勬槸<鐢熶骇鑰咃紝鑺傜偣鏈€鍚庡崟鑺傜偣涓嶅彲閫嗗彿> 瀵癸紝瀹瑰櫒鐨勫埌灏忕瓑浜巃ctive_schedule閲岀敓浜ц妭鐐圭殑鏁伴噺銆?锛娿€€鏋勯€犱簡blocknums锛伙冀鏁扮粍锛屽皢new_producer_to_last_implied_irb涓殑鍗曡妭鐐逛笉鍙€嗗彿澶嶅埗鍒伴噷闈紝鎵€浠ヨ繖閲宐locknums鐨勫ぇ灏忎篃绛変簬瀹為檯鐢熶骇鑺傜偣鐨勫ぇ灏忋€?锛娿€€灏哹locknums鎸変粠灏忓埌澶х殑椤哄簭鎺掑簭锛屽彇鍏?blocknums.size()-1) / 3浣嶇疆鐨勫潡鍙凤紝鎴愪负鍏ㄧ綉涓嶅彲閫嗗潡鍙枫€?銆€
銆€浠ワ紥锛戜釜鐢熶骇鑺傜偣涓轰緥锛?blocknums.size()-1) / 3銆€锛濓紪锛宐locknums锛伙紪锛戒綅缃殑鍧楀彿锛岀储寮曚粠锛愬紑濮嬶紝鍗充粠鍧楀彿浠庡ぇ鍒板皬鎺掔锛戯紩涓妭鐐圭殑鍧楀彿锛岀敱鎷滃崰搴叡璇嗙畻娉曪紥锛懨楋紥/ 3锛嬶紤锛濓紤锛曪紝鍙互鐪嬪嚭锛屾澶勮绠楄櫧鐒舵槸鍙栫殑锛? 3澶勭殑鍧楀彿锛屼絾瀹冩槸閫嗗簭鍙栫殑锛屾墍浠ョ浜岃疆鍏辫瘑瀹為檯涔熸槸涓€娆℃嫓鍗犲涵鍏辫瘑銆?
杩欓噷杩樻湁涓€涓敞鎰忕偣锛屽湪杩涜鐢熶骇鑺傜偣鍒囨崲鏈夋柊鑺傜偣鍔犲叆鏃讹紝producer_to_last_implied_irb涓柊鍔犲叆鑺傜偣鐨勫崟鑺傜偣涓嶅彲閫嗗潡鍙蜂細浣跨敤褰撳墠閾惧ご鍙疯繘琛屽垵濮嬪寲銆?
```c++
flat_map<account_name,uint32_t> new_producer_to_last_implied_irb;
for( const auto& pro : active_schedule.producers )
auto existing = producer_to_last_implied_irb.find( pro.producer_name );
if( existing != producer_to_last_implied_irb.end() )
new_producer_to_last_implied_irb[pro.producer_name] = existing->second;
else
new_producer_to_last_implied_irb[pro.producer_name] =
dpos_irreversible_blocknum;
3.2 楠岃瘉鑺傜偣鍏辫瘑
銆€銆€楠岃瘉鑺傜偣鏀跺埌鍧楋紝浼氭牴鎹潡澶翠腑鐨刢onfirmed鍙橀噺锛屽嵆璇ュ潡宸茬‘璁ゅ潡鏁帮紝鍦ㄦ湰鑺傜偣閲嶅仛璇ュ潡鐨勫叡璇嗚繃绋嬶紝浠ヤ繚璇佽妭鐐圭殑鐘舵€佷竴鐩存€с€傜敓浜ц妭鐐规敹鍒板潡锛屽皢鍧楁斁鍏ork_db鏃讹紝浼氳皟鐢╝pply_block()鍑芥暟锛岃繘琛屽潡楠岃瘉锛岄獙璇佽繃绋嬩細璋冪敤controller_impl::start_block()鍑芥暟锛屾瀯閫犲潡鐨勯獙璇佺幆澧冦€?/p>
```c++
void apply_block( const signed_block_ptr& b, controller::block_status s )
......
auto producer_block_id = b->id();
//楠岃瘉鍧楀墠锛岄渶鏋勯€爌endding鍧楃幆澧?br/>start_block( b->timestamp, b->confirmed, s , producer_block_id);
//楠岃瘉浜ゆ槗
......
杩欎釜start_block()鍜屽嚭鍧楁椂璋冪敤鐨剆tart_block()鏄悓涓€鍑芥暟锛屾墍浠ュ墠闈㈣繘琛岀殑涓よ疆鍏辫瘑璁$畻锛岃繖閲屼篃浼氬仛涓€閬嶃€傚彧鏄繖娆″仛鏄负浜嗗拰鍑哄潡鑺傜偣淇濇寔鐘舵€佷竴鐩达紝鍋氱殑鏄疄闄呭嚭鍧楄€呯殑鍏辫瘑杩囩▼锛屽苟涓嶄唬琛ㄦ湰鑺傜偣鍏辫瘑浜嗙浉搴斿潡銆傛洿鏂扮殑涓嶅彲閫嗗潡鍙蜂篃鏄疄闄呭嚭鍧楄€呯殑鍊笺€?
### **4 eos鍧楄惤宸?36**
eos涓槸21涓妭鐐瑰嚭鍧楋紝姣忎釜鑺傜偣杩炵画鍑?2涓潡锛屽垏鎹笅涓敓浜ц€呫€傛瘡涓潡闇€瑕侊細21*2/3 +1 =15涓妭鐐瑰叡璇嗐€?
? 涓嬪浘涓篹os鑺傜偣鍑哄潡搴忓彿琛ㄥ睍绀猴紝鑺傜偣1绗竴杞嚭1-12鍧楋紝鎺ョ潃鑺傜偣2鍑?1-24鍧楋紝鍥句腑pirb涓哄崟鑺傜偣涓嶅彲閫嗗潡鍙凤紝irb涓哄叏缃戜笉鍙€嗗潡鍙枫€?![](https://s1.51cto.com/images/blog/201908/29/35e8e75e0c692bf04a57cae32caf03d1.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
* 鑺傜偣1鍑? - 12鍧楋紝闇€瑕佸寘鎷嚜宸卞湪鍐呯殑15涓妭鐐圭‘璁わ紝鍒欏埌鑺傜偣15鍑虹169鍧楁椂锛?-12鍧楀彉鎴愬崟鑺傜偣涓嶅彲閫嗗潡锛岃妭鐐?5鐨刾irb=12锛?* 浠ユ绫绘帹锛?6鍙疯妭鐐圭敓浜ф椂锛?4鍙峰潡鎴愪负鍗曡妭鐐逛笉鍙€嗭紝... 锛岃妭鐐?绗簩杞敓浜?37鍧楁椂锛?70鍧楁垚涓哄崟鑺傜偣涓嶅彲閫嗐€傛寜绗簩杞叡璇嗭紝鎶?1涓妭鐐圭殑鍗曡妭鐐逛笉鍙€嗗彿鏀惧叆blocknums[21]鏁扮粍鎺掑簭锛宐locknums閲岄潰鐨勬暟鎹氨鏄浘涓璸irb妗旇壊搴曡壊鐨勫€笺€傚彇blocknums[(21-1)/3] 鐨勫潡鍙锋垚涓哄崟鑺傜偣涓嶅彲閫嗗彿銆?i=6澶勭殑鍧楀彿12鎴愪负鍏ㄧ綉涓嶅彲閫嗗潡銆?* 337鍧楃敓浜у墠锛岀郴缁熶腑宸茬粡鐢熶骇浜?36涓潡锛屼絾娌℃湁涓€涓潡鎴愪负涓嶅彲閫嗚惤鍧楋紝鐩村埌337鍧楃敓浜у紑濮嬶紝绯荤粺涓墠棣栨鍑虹幇鍏ㄧ綉涓嶅彲閫嗗潡钀藉潡銆傚緱鍒癳os绯荤粺鏈€澶у潡钀藉樊336銆?
### 5 閾炬帴
[鏄熸渤鍏摼](http://www.3heu.com/)
以上是关于EOS鍏辫瘑鎬荤粨的主要内容,如果未能解决你的问题,请参考以下文章