Skip to content

Commit

Permalink
feat: remove cellbase_id from header
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Mar 27, 2019
1 parent be44a60 commit 528e95e
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 87 deletions.
3 changes: 1 addition & 2 deletions chain/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ pub(crate) fn gen_block(
.parent_hash(parent_header.hash().clone())
.timestamp(unix_time_as_millis())
.number(number)
.difficulty(difficulty)
.cellbase_id(cellbase.hash());
.difficulty(difficulty);

BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down
12 changes: 0 additions & 12 deletions core/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ pub struct RawHeader {
txs_proposal: H256,
/// Block difficulty.
difficulty: U256,
/// Hash of the cellbase
cellbase_id: H256,
/// Hash of the uncles
uncles_hash: H256,
/// Number of the uncles
Expand Down Expand Up @@ -113,7 +111,6 @@ impl fmt::Debug for Header {
&format_args!("{:#x}", self.raw.txs_proposal),
)
.field("difficulty", &format_args!("{:#x}", self.raw.difficulty))
.field("cellbase_id", &format_args!("{:#x}", self.raw.cellbase_id))
.field("uncles_hash", &format_args!("{:#x}", self.raw.uncles_hash))
.field("uncles_count", &self.raw.uncles_count)
.field("seal", &self.seal)
Expand Down Expand Up @@ -174,10 +171,6 @@ impl Header {
&self.raw.txs_proposal
}

pub fn cellbase_id(&self) -> &H256 {
&self.raw.cellbase_id
}

pub fn uncles_hash(&self) -> &H256 {
&self.raw.uncles_hash
}
Expand Down Expand Up @@ -268,11 +261,6 @@ impl HeaderBuilder {
self
}

pub fn cellbase_id(mut self, hash: H256) -> Self {
self.inner.raw.cellbase_id = hash;
self
}

pub fn uncles_hash(mut self, hash: H256) -> Self {
self.inner.raw.uncles_hash = hash;
self
Expand Down
2 changes: 0 additions & 2 deletions docs/data-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ More information about the Transaction of Nervos CKB can be found in [whitepaper
}
],
"header": {
"cellbase_id": "0xabeb06aea75b59ec316db9d21243ee3f0b0ad0723e50f57761cef7e07974b9b5",
"difficulty": "0x100",
"hash": "0xcddd882eff5edd2f7db25074cbbdc1d21cd698f60d6fb39412ef91d19eb900e8",
"number": 11,
Expand Down Expand Up @@ -230,7 +229,6 @@ More information about the Transaction of Nervos CKB can be found in [whitepaper

| Name | Type | Description |
| -------------- | ------------------- | ------------------------------------------------------------ |
| `cellbase_id` | H256(hash) | **The hash of the Cellbase transaction.** Cellbase transaction is just like the coinbase transaction in Bitcoin. It's the transaction added by the miner who mined this block, by which the miner receives block reward for successfully mined the block. |
| `difficulty` | Bytes | **The difficulty of the PoW puzzle.** |
| `hash` | H256(hash) | **The block hash.** Note that although this value is returned by the JSON-RPC API, it is in fact NOT a part of the header. This value is actually calculated from the `Header` data. |
| `number` | uint64 | **The block height.** |
Expand Down
9 changes: 4 additions & 5 deletions miner/src/block_assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,17 @@ mod tests {
// uncles_count_limit,
} = block_template;

let (cellbase_id, cellbase) = {
let CellbaseTemplate { hash, data, .. } = cellbase;
(hash, data)
let cellbase = {
let CellbaseTemplate { data, .. } = cellbase;
data
};

let header_builder = HeaderBuilder::default()
.version(version)
.number(number)
.difficulty(difficulty)
.timestamp(current_time)
.parent_hash(parent_hash)
.cellbase_id(cellbase_id);
.parent_hash(parent_hash);

let block = BlockBuilder::default()
.uncles(uncles.into_iter().map(Into::into).collect())
Expand Down
9 changes: 4 additions & 5 deletions miner/src/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ impl Miner {
// uncles_count_limit,
} = template;

let (cellbase_id, cellbase) = {
let CellbaseTemplate { hash, data, .. } = cellbase;
(hash, data)
let cellbase = {
let CellbaseTemplate { data, .. } = cellbase;
data
};

let header_builder = HeaderBuilder::default()
.version(version)
.number(number)
.difficulty(difficulty)
.timestamp(current_time)
.parent_hash(parent_hash)
.cellbase_id(cellbase_id);
.parent_hash(parent_hash);

let block = BlockBuilder::default()
.uncles(uncles.into_iter().map(Into::into).collect())
Expand Down
1 change: 0 additions & 1 deletion nodes_template/spec/dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ timestamp = 0
txs_commit = "0x0000000000000000000000000000000000000000000000000000000000000000"
txs_proposal = "0x0000000000000000000000000000000000000000000000000000000000000000"
difficulty = "0x100"
cellbase_id = "0x0000000000000000000000000000000000000000000000000000000000000000"
uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"

[genesis.seal]
Expand Down
2 changes: 0 additions & 2 deletions protocol/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl<'a> FbsHeader<'a> {
let txs_proposal = header.txs_proposal().into();
let difficulty = FbsBytes::build(fbb, &uint_to_bytes(header.difficulty()));
let proof = FbsBytes::build(fbb, &header.proof());
let cellbase_id = header.cellbase_id().into();
let uncles_hash = header.uncles_hash().into();
let mut builder = HeaderBuilder::new(fbb);
builder.add_version(header.version());
Expand All @@ -61,7 +60,6 @@ impl<'a> FbsHeader<'a> {
builder.add_difficulty(difficulty);
builder.add_nonce(header.nonce());
builder.add_proof(proof);
builder.add_cellbase_id(&cellbase_id);
builder.add_uncles_hash(&uncles_hash);
builder.add_uncles_count(header.uncles_count());
builder.finish()
Expand Down
2 changes: 0 additions & 2 deletions protocol/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ impl<'a> TryFrom<ckb_protocol::Header<'a>> for ckb_core::header::Header {
let parent_hash = cast!(header.parent_hash())?;
let txs_commit = cast!(header.txs_commit())?;
let txs_proposal = cast!(header.txs_proposal())?;
let cellbase_id = cast!(header.cellbase_id())?;
let uncles_hash = cast!(header.uncles_hash())?;

Ok(ckb_core::header::HeaderBuilder::default()
Expand All @@ -164,7 +163,6 @@ impl<'a> TryFrom<ckb_protocol::Header<'a>> for ckb_core::header::Header {
.difficulty(U256::from_little_endian(cast!(header
.difficulty()
.and_then(|d| d.seq()))?)?)
.cellbase_id(TryInto::try_into(cellbase_id)?)
.uncles_hash(TryInto::try_into(uncles_hash)?)
.nonce(header.nonce())
.proof(cast!(header
Expand Down
1 change: 0 additions & 1 deletion protocol/src/protocol.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ table Header {
difficulty: Bytes;
nonce: uint64;
proof: Bytes;
cellbase_id: H256;
uncles_hash: H256;
uncles_count: uint32;
}
Expand Down
16 changes: 2 additions & 14 deletions protocol/src/protocol_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,6 @@ impl<'a> Header<'a> {
builder.add_timestamp(args.timestamp);
builder.add_uncles_count(args.uncles_count);
if let Some(x) = args.uncles_hash { builder.add_uncles_hash(x); }
if let Some(x) = args.cellbase_id { builder.add_cellbase_id(x); }
if let Some(x) = args.proof { builder.add_proof(x); }
if let Some(x) = args.difficulty { builder.add_difficulty(x); }
if let Some(x) = args.txs_proposal { builder.add_txs_proposal(x); }
Expand All @@ -1043,9 +1042,8 @@ impl<'a> Header<'a> {
pub const VT_DIFFICULTY: flatbuffers::VOffsetT = 16;
pub const VT_NONCE: flatbuffers::VOffsetT = 18;
pub const VT_PROOF: flatbuffers::VOffsetT = 20;
pub const VT_CELLBASE_ID: flatbuffers::VOffsetT = 22;
pub const VT_UNCLES_HASH: flatbuffers::VOffsetT = 24;
pub const VT_UNCLES_COUNT: flatbuffers::VOffsetT = 26;
pub const VT_UNCLES_HASH: flatbuffers::VOffsetT = 22;
pub const VT_UNCLES_COUNT: flatbuffers::VOffsetT = 24;

#[inline]
pub fn version(&self) -> u32 {
Expand Down Expand Up @@ -1084,10 +1082,6 @@ impl<'a> Header<'a> {
self._tab.get::<flatbuffers::ForwardsUOffset<Bytes<'a>>>(Header::VT_PROOF, None)
}
#[inline]
pub fn cellbase_id(&self) -> Option<&'a H256> {
self._tab.get::<H256>(Header::VT_CELLBASE_ID, None)
}
#[inline]
pub fn uncles_hash(&self) -> Option<&'a H256> {
self._tab.get::<H256>(Header::VT_UNCLES_HASH, None)
}
Expand All @@ -1107,7 +1101,6 @@ pub struct HeaderArgs<'a> {
pub difficulty: Option<flatbuffers::WIPOffset<Bytes<'a >>>,
pub nonce: u64,
pub proof: Option<flatbuffers::WIPOffset<Bytes<'a >>>,
pub cellbase_id: Option<&'a H256>,
pub uncles_hash: Option<&'a H256>,
pub uncles_count: u32,
}
Expand All @@ -1124,7 +1117,6 @@ impl<'a> Default for HeaderArgs<'a> {
difficulty: None,
nonce: 0,
proof: None,
cellbase_id: None,
uncles_hash: None,
uncles_count: 0,
}
Expand Down Expand Up @@ -1172,10 +1164,6 @@ impl<'a: 'b, 'b> HeaderBuilder<'a, 'b> {
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<Bytes>>(Header::VT_PROOF, proof);
}
#[inline]
pub fn add_cellbase_id(&mut self, cellbase_id: &'b H256) {
self.fbb_.push_slot_always::<&H256>(Header::VT_CELLBASE_ID, cellbase_id);
}
#[inline]
pub fn add_uncles_hash(&mut self, uncles_hash: &'b H256) {
self.fbb_.push_slot_always::<&H256>(Header::VT_UNCLES_HASH, uncles_hash);
}
Expand Down
2 changes: 0 additions & 2 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block","params": ["0x087c25e2
}
],
"header": {
"cellbase_id": "0x3abd21e6e51674bb961bb4c5f3cee9faa5da30e64be10628dc1cef292cbae324",
"difficulty": "0x100",
"hash": "0x087c25e23e42f5d1e00e6984241b3711742d5e0eaf75d79a427276473e1de3f9",
"number": 1,
Expand Down Expand Up @@ -155,7 +154,6 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_tip_header","params": []}' -H
{
"jsonrpc": "2.0",
"result": {
"cellbase_id": "0xa4ecd25e3b572dc078cf000bfa1d81f1b578eeb5245c166353682919d37ebf42",
"difficulty": "0x100",
"hash": "0x44483beaf890d4aac2b2df90a50d9236db4a810d08f0912c1981f4a1db8086fd",
"number": 37,
Expand Down
2 changes: 0 additions & 2 deletions spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub struct Genesis {
pub txs_commit: H256,
pub txs_proposal: H256,
pub difficulty: U256,
pub cellbase_id: H256,
pub uncles_hash: H256,
}

Expand Down Expand Up @@ -115,7 +114,6 @@ impl ChainSpec {
.difficulty(self.genesis.difficulty.clone())
.nonce(self.genesis.seal.nonce)
.proof(self.genesis.seal.proof.to_vec())
.cellbase_id(self.genesis.cellbase_id.clone())
.uncles_hash(self.genesis.uncles_hash.clone())
.build();

Expand Down
1 change: 0 additions & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ pub mod test {
txs_commit = "0x0000000000000000000000000000000000000000000000000000000000000000"
txs_proposal = "0x0000000000000000000000000000000000000000000000000000000000000000"
difficulty = "0x233"
cellbase_id = "0x0000000000000000000000000000000000000000000000000000000000000000"
uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
[genesis.seal]
Expand Down
1 change: 0 additions & 1 deletion sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,6 @@ mod tests {
.timestamp(now)
.number(number)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone())
.nonce(nonce);

BlockBuilder::default()
Expand Down
15 changes: 5 additions & 10 deletions sync/src/tests/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ fn relay_compact_block_with_one_tx() {
.parent_hash(last_block.header().hash().clone())
.number(number)
.timestamp(timestamp)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone());
.difficulty(difficulty);

BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down Expand Up @@ -129,8 +128,7 @@ fn relay_compact_block_with_one_tx() {
.parent_hash(last_block.header().hash().clone())
.number(number)
.timestamp(timestamp)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone());
.difficulty(difficulty);

BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down Expand Up @@ -248,8 +246,7 @@ fn relay_compact_block_with_missing_indexs() {
.parent_hash(last_block.header().hash().clone())
.number(number)
.timestamp(timestamp)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone());
.difficulty(difficulty);

BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down Expand Up @@ -287,8 +284,7 @@ fn relay_compact_block_with_missing_indexs() {
.parent_hash(last_block.header().hash().clone())
.number(number)
.timestamp(timestamp)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone());
.difficulty(difficulty);

BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down Expand Up @@ -373,8 +369,7 @@ fn setup_node(
.parent_hash(block.header().hash().clone())
.number(number)
.timestamp(timestamp)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone());
.difficulty(difficulty);

block = BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down
3 changes: 1 addition & 2 deletions sync/src/tests/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ fn setup_node(
.parent_hash(block.header().hash().clone())
.number(number)
.timestamp(timestamp)
.difficulty(difficulty)
.cellbase_id(cellbase.hash().clone());
.difficulty(difficulty);

block = BlockBuilder::default()
.commit_transaction(cellbase)
Expand Down
1 change: 0 additions & 1 deletion test/fixtures/nodes_template/spec/integration_test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ timestamp = 0
txs_commit = "0x0000000000000000000000000000000000000000000000000000000000000000"
txs_proposal = "0x0000000000000000000000000000000000000000000000000000000000000000"
difficulty = "0x100"
cellbase_id = "0x0000000000000000000000000000000000000000000000000000000000000000"
uncles_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"

[genesis.seal]
Expand Down
7 changes: 3 additions & 4 deletions test/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ impl Node {
..
} = template;

let (cellbase_id, cellbase) = {
let CellbaseTemplate { hash, data, .. } = cellbase;
(hash, data)
let cellbase = {
let CellbaseTemplate { data, .. } = cellbase;
data
};

let header_builder = HeaderBuilder::default()
Expand All @@ -163,7 +163,6 @@ impl Node {
.difficulty(difficulty)
.timestamp(current_time)
.parent_hash(parent_hash)
.cellbase_id(cellbase_id)
.seal(Seal::new(rand::random(), Vec::new()));

BlockBuilder::default()
Expand Down
Loading

0 comments on commit 528e95e

Please sign in to comment.