Brother even blockchain tutorial Btcpool the core mechanism of source code analysis of mine pool and its optimization thinking

Source: Internet
Author: User

Summary of core mechanism and optimization thinking of Btcpool mine pool--summary ①gbtmaker
    • Listen for Bitcoind_zmq_hashblock messages in Bitcoind ZMQ, a new block is generated, and a new GBT is immediately sent to Kafka
    • Also default every 5 seconds interval (can be specified from the configuration file) active RPC request Bitcoind, get GBT sent to Kafka
    • GBT message size approx. 2M, including trade list
②jobmaker
    • Simultaneous monitoring of KAFKA KAFKA_TOPIC_RAWGBT and Kafka_topic_nmc_auxblock to support mixed mining
    • GBT messages received if the delay exceeds 60 seconds with local time will be discarded if the delay exceeds 3 seconds will print log
    • The available GBT messages will be gbttime+isemptyblock+height to construct the key to write to the local map, and the Gbthash will write to the local queue
    • Local Gbthash queues save only the last 20, local gbtmap GBT message validity: Non-empty GBT valid for 90 seconds, empty GBT valid for 15 seconds, expiration clears
      ???? * Validity period can be specified from the configuration file
    • GBT message if the height is lower than the local GBT height, and the local GBT is not empty, and not more than twice times the local time interval STRATUMJOBINTERVAL_,GBT message will be discarded
    • In three cases, the stratumjob will be sent to Kafka immediately:
      ???? height greater than local height (that is, new blocks found)
      ????
      The height is the same as the local height, but the previous job is an empty block job, but the new GBT non-empty block
      ???? * Reach the scheduled time interval of 20 seconds (can be specified from the configuration file)
③sserver
  • The received job delay will be discarded for more than 60 seconds
  • If the Prevhash in the job is different from the local job Prevhash, the Isclean state in the job is set to true if a new block has been generated
    ???? * True requires the miner to switch job immediately
  • In three cases, a new job will be issued to the miner:
    ???? receive new heights of job
    ????
    The last job is a new height and is empty block job, and the latest job is a non-empty block job
    ???? * Reach the scheduled time interval of 30 seconds
  • The last time the job was issued will be written to the file (specified by File_last_notify_time)
  • Local job is valid for 300 seconds
  • Pull a new user list every 10 seconds (specified by List_id_api_url), which the user writes to the local map
  • Sserver Maximum available SessionID number is 16777214
  • Btcpool supports btcagent extension protocol and stratum protocol, using Magic_number (0x7F) to differentiate
  • Processing the stratum protocol:
    ???? The Suggest_target is equivalent to Suggest_difficulty, which is used to set the initial mining difficulty, and needs to be requested before subscribe
    ????
    Use SessionID as extranonce1_ to ensure that the mining machine tasks are not duplicated
    ???? 15-Second read timeout before authorize, 10-minute read timeout after authorize, 10-minute no commit disconnects
    ????
    Initial difficulty is 16384, or specified from Suggest_difficulty, the next time the adjustment is in place hold 10s commit share
    ???? * Each session will maintain a localjobs_ queue with a queue length of 10
  • Share are rejected in several cases:
    ???? the JOB has been extruded in the Job_not_found,localjobs_ queue
    ????
    DUPLICATEShare,share has been submitted, the submitted SHARE accounting into Submitshares
    ???? job does not exist in Job_not_found,jobrepository_, that is, the job has expired (300-second expiration time)
    ????
    Job_not_found,jobrepository_ job status is stale, that is, the job is an old non-new job
    ???? the Ntime submitted in Time_too_old,share is less than the mintime of the job provision
    ????
    The Ntime submitted in Time_too_old,share is 10 minutes larger than the current time
    ???? * The hash submitted in Low_difficulty,share does not meet the difficulty target
  • To process the btcagent extension protocol:
    ???? Agent under the mining machine default difficulty is also 16384
    ????
    Use Agent SessionID as the first half of the extranonce2_ to ensure that the agent does not duplicate the mining machine task
    ???? When a new task is issued in a mine pool, such as the session is btcagent, it will be difficult for all the miners under the agent.
    ????????
    If the difficulty changes, will be different difficulty, the construction of multiple Cmd_mining_set_diff instructions are issued together with the processing
④blkmaker
    • Blkmaker can connect multiple bitcoind nodes
    • Blkmaker Listen and receive 4 types of messages: RAWGBT, Stratum_job, Solved_share, and Nmc_solved_share
    • Listener RAWGBT Purpose to get a list of gbthash/transactions for building Block,gbthash and Vtxs write RAWGBTMAP_
      ???? * RAWGBTMAP_ Save the last 100 Gbthash/vtxs
    • Listenfor stratum job purpose to get jobId/gbthash,jobid and Gbthash write Jobid2gbthash
      ???? * Jobid2gbthash Save the last 120 Jobid/gbthash
    • Monitoring Solved_share purpose for obtaining blockheader and Coinbasetx
      ???? * BLOCKHEADER+COINBASETX+VTXS Construction Block
    • The constructed block commits all bitcoind nodes that are connected
    • Constructed block warehousing, inbound fields include:
      ???? Puid, worker_id, Worker_full_name, job_id, height, hash
      ????
      Rewards (i.e. Coinbasevalue), size (i.e. blksize), Prev_hash, Bits, version, Created_at
      ???? * Created_at for storage time non-burst block time
      ????

      ⑤sharelogger
    • Receive shareLOG, write shares, write to file every 2 seconds (path specified by Data_dir)
      ???? a new file every day, the file name is like: Sharelog-2016-07-12.bin
      ????
      Maintain file handles for up to 3 days
⑥slparser
    • Supports three functions:
      ???? Specifies the date and UID that will print the share information for the specified user to stdout
      ????????
      Uid=0, the share information for all users of the specified date will be printed
      ???? Specifies date but does not specify UID, reads Sharelog, statistics data and writes to database
      ????????
      Statistics by worker, user, pool three dimensions: accept1h, ACCEPT1D, score1h, score1d, reject1h, REJECT1D
      ???????? The database retains only the last 3 months of statistical data
      ????
      If neither date nor UID is specified, the file will be monitored for changes, read share and statistics, written to the database every 15 seconds
      ???????? * Start httpd service at the same time, open Serverstatus and Workerstatus
⑦statshttpd
    • Listen and receive shareLOG, press worker, user, pool statistics acceptcount, Acceptsharesec, Rejectsharemin
      ???? simultaneous statistics Totalworkercount and TotalUserCount
      ????
      Share_log with a delay of more than 1 hours will be ignored
    • Every 15s write database (can be specified by flush_dbinterval), cleanup of expired worker every 30 minutes
      ???? If the worker does not commit share for more than 1 hours, it will be set to an out-of-date status
      ????
      Calculate accept1m
      , accept5m, accept15m, reject15m, accept1h, reject1h for each worker
      ???????? * and Acceptcount
      , Lastshareip, Lastsharetime
      ???? drop and create data table Mining_workers_tmp,worker statistics bulk Write mining_workers_tmp
      ????
      Mining_workers_tmp data is written to the data table Mining_workers
    • Listen and receive common_events, get workername and mineragent, update datasheet mining_workers
    • Start httpd Service, open Serverstatus and Workerstatus
⑧poolwatcher
    • Monitor Stratumjob, update poolstratumjob_, for comparison with third-party pool
    • Connecting a third-party pool as a client, such as a mining mission, will be constructed only if the received job height = local Pool job height + 1 o'clock EMPTYGBT
    • A job received from a third-party pool will be discarded in the following cases:
      ???? job height is the same as for local mine pool job
      ????
      Job height is not equal to local mine pool job height +1, height jump too big
      ???? * Nbits is different from local mine pool job nbits

Brother even blockchain tutorial Btcpool the core mechanism of source code analysis of mine pool and its optimization thinking

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.