Open andrewvy opened 7 years ago
IT'S ALIVE
kinda
empty txless block mining on local (no-net)
┌──────────────────────────────────────────┐ ┌──────────────────────────────────────────┐
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ │ │ │
│ Opal Daemon │ │ Opal Peer │
│ │ P2P Layer │ │
│ │ │ │
│ │ │ │
├────────────┐ ┌────────────┤ │ ┌────────────┤
│Internal RPC│ │External RPC│ │ │External RPC│
│ (9898) │ │ (9899) │ │ │ (9899) │
└────────────┴────────────────┴────────────┘ └─────────────────────────────┴────────────┘
│ │ ▲
│ │ │
│ ├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
│ │ Protobuf over HTTP
│ │ ┌──────────────────────────────────────────┐
Protobuf over HTTP│ │ │ │
Client Agnostic RPC Layer ┌──────────────────┤ │ │ │
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
│ │ │ │ │
│ │ │ │ Opal Peer │
│ │ │ │ │
▼ ▼ │ │ │
┌───────────┐ ┌───────────────┐ │ │ │
│Rust Client│ │Built-in Client│ │ │ ┌────────────┤
└───────────┘ └───────────────┘ │ │ │External RPC│
│ │ │ (9899) │
│ └─────────────────────────────┴────────────┘
│ ▲
│ │
├─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
│
│ ┌──────────────────────────────────────────┐
│ │ │
┌─────────────────────────┐ │ │ │
│ Initialization Sequence │ │ │ │
└─────────────────────────┘ │ │ │
│ │ │
│ │ │
1) Get external facing IP address using UPnP │ │ Opal Peer │
│ │ │
2) Broadcast 'Peer Advertise' message with │ │ │
external IP │ │ │
│ │ ┌────────────┤
3) Call 'Peer List' on seed DNS nodes and keep │ │ │External RPC│
track in a local list of peers, also saved for │ │ │ (9899) │
later peer discovery seed usage. │ └─────────────────────────────┴────────────┘
│ ▲
4) Start downloading block headers from peers │ │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
5) Validate headers and figure out the 'best
header chain'
6) Once best header chain has been found, start
downloading full blocks from peers.
7) Start validating full blocks and maintain a
UXTO database
8) You are ready to start accepting TXs and
Blocks!
transactions
transaction_from_serialized
(convert serialized protobuf into transaction struct)verify_txin
(verifies txin is valid, that it points to an unspent txout)blocks
block_to_proto
(convert block struct into proto struct)block_to_serialized
(convert block struct into serialized)block_from_serialized
(convert serialized protobuf into block struct)compute_merkle_root
(computes merkle root)verify_merkle_root
(verifies merkle root)verify_block
(verify entire block, its txin, merkle root, whole boi)blockchain
insert_block_into_blockchain
(serializes block, puts serialized block into blockchain db)fetch_block_from_db
(fetches block struct, deserializing from db using passed in hash)get_block_from_tx
(fetches block struct from a TX struct)get_block_height_for_block
(gets the block height to a certain block hash, used for determining best blockchain)remove_block_from_db
undo_block
(must go through blocks if new branch is valid, undo old blocks, apply new branch)insert_tx_into_index
(if block is inserted into chain, add index for those block's txs to point to the block hash)transaction index
. TX hash as key, value points to block key where TX is locatedget_blocks_since_hash
gets future blocks from a given start hash, returns a set size (iterates over all blocks to find start hash, while buffering blocks)api