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鍧楋細

鎶€鏈浘鐗? src=

1 璁$畻鑺傜偣1鏈‘璁ゅ潡鏁帮細鐩墠閾惧ご鍧楀潡鍙? - 鑺傜偣姘村嵃鍊?锛堣妭鐐?鐢熶骇鐨勬渶鍚庝竴涓潡锛?4锛?/p>

? 鍗崇敓浜?鍙峰潡鏃讹紝鍓嶉潰鏈?涓潡寰呰妭鐐?纭銆?/p>

2 璁$畻7鍙峰潡闇€瑕佽鍑犱釜鑺傜偣纭锛? 3锛堣妭鐐规暟)* 2/3 +1 = 3锛屽皢3鏀惧叆confirm_count[]鏈€鍚庯紱

3 绗竴杞叡璇嗚绠楋細瀹為檯灏辨槸瀵筩onfirm_count[]鏁扮粍涓繚瀛樼殑寰呯‘璁ゆ暟杩涜鍑?璁$畻銆?/p>

? 鍧楀緟纭鏁扮粍confirm_count[] 鍦ㄧ涓€杞叡璇嗕腑鐨勫彉鍔ㄦ儏鍐靛睍绀哄涓嬶細
鎶€鏈浘鐗? src=

  1. 鐢熶骇7鍧楀墠锛岄噷闈㈡湁4涓緟纭鍧椼€?/li>
  2. 鍏堝皢7鍧楃殑寰呯‘璁ゆ暟3鎻抍onfirm_count鐨勬渶鍚庛€?/li>
  3. 寰幆浠巆onfirm_count[]灏鹃儴瀵瑰叾涓殑鍊兼墽琛屽噺1鎿嶄綔銆傚綋鏈塩onfirm_count[i]==0鎴愮珛锛屽仠姝㈠惊鐜€俰浣嶇疆瀵瑰簲鐨勫潡鍙凤紝鍗虫娆″叡璇嗗緱鍒扮殑鍗曡妭鐐逛笉鍙€嗗潡鍙凤紝姝ゆ椂4鍙峰潡鎴愪负鍗曡妭鐐逛笉鍙€嗗潡锛屽畠涔嬪墠鐨勫潡涓嶇敤璁$畻锛岄兘鑷姩鎴愪负鍗曡妭鐐逛笉鍙€嗗潡銆?/li>
  4. 绉诲姩confirm_count[],娓呴櫎4鍙峰潡涔嬪墠鎵€鏈夊潡銆?/li>

绗竴杞叡璇嗗畬鎴?寰楀埌dpos_proposed_irreversible_blocknum=4銆?/p>

绗簩杞叡璇?/p>

? 杩欓噷涓昏鐢ㄥ埌producer_to_last_implied_irb锛屽畠鏄竴涓猰ap瀹瑰櫒锛岄噷闈㈡斁鐨勬槸鐢熶骇鑺傜偣鐨勮妭鐐瑰悕鍙婅鑺傜偣瀵瑰簲鐨勫崟鐐逛笉鍙€嗗潡鍙凤紝姝ゅ鐨勫崟鐐逛笉鍙€嗗潡鍙峰氨鏄鑺傜偣鍦ㄦ墽琛岀涓€杞叡璇嗚绠楁椂寰楀埌鐨勫€笺€傚彧鏈夊嚭鍧楄妭鐐圭殑鍗曡妭鍗曡妭鐐逛笉鍙€嗗€兼墠浼氭洿鏂般€?/p>

鍒氭墠鐢熶骇7鍙峰潡鏃惰绠楀緱鍒拌妭鐐?鐨勫綋鍓嶄笉鍙€嗗潡鍙锋槸4锛屽彲鎺ㄥ緱姝ゆ椂鑺傜偣3瀵瑰簲鐨勫€煎簲璇ユ槸2锛岃妭鐐?瀵瑰簲鍊?銆傚綋鑺傜偣2鐢熶骇绗?涓潡鏃讹紝鑺傜偣2绗竴杞叡璇嗗緱鍒扮殑鍗曡妭鐐逛笉鍙€嗗潡鍙?锛?鍏跺畠鑺傜偣涓嶅彉锛屽涓嬪浘鎵€绀猴細
鎶€鏈浘鐗? src=

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>

鎶€鏈浘鐗? src=

? 涓嬪浘涓烘牴鎹甧os鍧楃敓浜ф祦绋嬬敾鍑虹殑鍧楀叡璇嗘祦绋嬶紝涓嬮潰鍒嗗埆浠庣敓浜ц妭鐐逛綔涓虹敓浜ц€呭嚭鍧楀拰浣滀负楠岃瘉鑺傜偣鏀跺埌涓ょ鎯呭喌锛岀粨鍚堜唬鐮佸垎鍒涓よ疆鍏辫瘑娴佺▼灞曞紑杩涜鍒嗘瀽銆?/p>

? 鑺傜偣浣滀负楠岃瘉鑺傜偣鏀跺埌鍧楋紝浼氳皟鐢╟onntroller_impl::apply_block锛堬級鍑芥暟锛屽鐞嗗潡涓暟鎹紝鏈€缁堣惤鍧椼€傚浘涓孩鑹插簳妗嗙殑鍐呭鏄涓€杞叡璇嗙敤鍒扮殑鍑芥暟鎴栧彉閲忥紝姗欒壊搴曟鍒欐槸绗簩杞叡璇嗙敤鍒扮殑銆?/p>

3.1 鍑哄潡鑺傜偣鍏辫瘑

3.1.1 绗竴杞叡璇?/h5>

? 鑺傜偣寰幆璋冪敤schedule_production_loop锛堬級鍑芥暟杩涜鐢熶骇寰幆锛屽嚱鏁颁腑浼氳皟鐢╯tart_block()鍒ゆ柇鏄惁璇ユ湰鑺傜偣鍑哄潡銆?/p>

  1. 璁$畻鏈潡闇€瑕佺‘璁ょ殑鍧楁暟锛歜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 )const

    block_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鍏辫瘑鎬荤粨的主要内容,如果未能解决你的问题,请参考以下文章

Java鎬荤粨

20191324銆婁俊鎭畨鍏ㄤ笓涓氬璁恒€嬬浜屽懆瀛︿範鎬荤粨

琛ㄦ牸鎬荤粨

SQL璇彞鎬荤粨

[鍘焆std::thread鎬荤粨