Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/res/null.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"seal": {
"generic": "0x0"
},
"score": "0x20000",
"author": "tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhn9p3",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
1 change: 0 additions & 1 deletion core/res/solo.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"seal": {
"generic": "0x0"
},
"score": "0x20000",
"author": "tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhn9p3",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
1 change: 0 additions & 1 deletion core/res/tendermint.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
]
}
},
"score": "0x20000",
"author": "tccq8qlwpt7xcs9lec3c8tyt3kqxlgsus8q4qp3m6ft",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
4 changes: 2 additions & 2 deletions core/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const BEST_PROPOSAL_BLOCK_KEY: &[u8] = b"best-proposal-block";
pub struct BlockChain {
/// The hash of the best block of the canonical chain.
best_block_hash: RwLock<BlockHash>,
/// The hash of the block which has the best score among the proposal blocks
/// The hash of the block which has the best possibility among the proposal blocks
best_proposal_block_hash: RwLock<BlockHash>,

headerchain: HeaderChain,
Expand Down Expand Up @@ -230,7 +230,7 @@ impl BlockChain {
{
cinfo!(
BLOCKCHAIN,
"Block #{}({}) has higher total score, changing the best proposal/canonical chain.",
"Block #{}({}) has higher block number and lower view, changing the best proposal/canonical chain.",
new_header.number(),
new_header.hash()
);
Expand Down
4 changes: 2 additions & 2 deletions core/src/blockchain/headerchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct HeaderChain {
// All locks must be captured in the order declared here.
/// The hash of the best block of the canonical chain.
best_header_hash: RwLock<BlockHash>,
/// The hash of the block which has the best score among the proposal blocks
/// The hash of the block which has the best possibility among the proposal blocks
best_proposal_header_hash: RwLock<BlockHash>,

// cache
Expand Down Expand Up @@ -287,7 +287,7 @@ impl HeaderChain {
if is_new_best {
ctrace!(
HEADERCHAIN,
"Block header #{}({}) has higher total score, changing the best proposal/canonical chain.",
"Block header #{}({}) has higher block number and lower view, changing the best proposal/canonical chain.",
new_header.number(),
new_header.hash()
);
Expand Down
15 changes: 5 additions & 10 deletions core/src/views/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use ccrypto::blake256;
use ckey::Address;
use ctypes::{BlockHash, BlockNumber};
use primitives::{Bytes, H256, U256};
use primitives::{Bytes, H256};
use rlp::Rlp;

/// View onto block header rlp.
Expand Down Expand Up @@ -75,29 +75,24 @@ impl<'a> HeaderView<'a> {
self.rlp.val_at(4).unwrap()
}

/// Returns block score.
pub fn score(&self) -> U256 {
self.rlp.val_at(5).unwrap()
}

/// Returns block number.
pub fn number(&self) -> BlockNumber {
self.rlp.val_at(6).unwrap()
self.rlp.val_at(5).unwrap()
}

/// Returns timestamp.
pub fn timestamp(&self) -> u64 {
self.rlp.val_at(7).unwrap()
self.rlp.val_at(6).unwrap()
}

/// Returns block extra data.
pub fn extra_data(&self) -> Bytes {
self.rlp.val_at(8).unwrap()
self.rlp.val_at(7).unwrap()
}

/// Returns a vector of post-RLP-encoded seal fields.
pub fn seal(&self) -> Vec<Bytes> {
const SIZE_WITHOUT_SEAL: usize = 9;
const SIZE_WITHOUT_SEAL: usize = 8;

let item_count = self.rlp.item_count().unwrap();
let mut seal = Vec::with_capacity(item_count - SIZE_WITHOUT_SEAL);
Expand Down
4 changes: 1 addition & 3 deletions rpc/src/v1/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::Transaction;
use ccore::{Block as CoreBlock, LocalizedTransaction};
use ckey::{NetworkId, PlatformAddress};
use ctypes::{BlockHash, BlockNumber};
use primitives::{H256, U256};
use primitives::H256;

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
Expand All @@ -34,7 +34,6 @@ pub struct Block {
state_root: H256,
next_validator_set_hash: H256,

score: U256,
seal: Vec<Vec<u8>>,

hash: BlockHash,
Expand Down Expand Up @@ -65,7 +64,6 @@ impl Block {
state_root: *block.header.state_root(),
next_validator_set_hash: *block.header.next_validator_set_hash(),

score: U256::default(),
seal: block.header.seal().to_vec(),

hash: block.header.hash(),
Expand Down
3 changes: 0 additions & 3 deletions spec/JSON-RPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ A string that starts with "(NetworkID)c", and Bech32 string follows. For example
- transactions: `Transaction[]`
- transactionsRoot: `H256`
- parentHash: `H256`
- score: `number`
- seal: `string[]`
- stateRoot: `H256`
- timestamp: `number`
Expand Down Expand Up @@ -567,7 +566,6 @@ Errors: `Invalid Params`
],
"transactionsRoot":"0xa4a8229a90d91e9a38b17f95c9ac2d01f46b10553e62c68df5bbfe1cc5b3e164",
"parentHash":"0xbc4f7e7b1dded863c500147243d78436ca297bfae64e1ec2d17396286cf14b6e",
"score":"0x20000",
"seal":[

],
Expand Down Expand Up @@ -629,7 +627,6 @@ Errors: `Invalid Params`
],
"transactionsRoot":"0x0270d11d2bd21a0ec8e78d1c4e918103d7c4b02fdf734051231cb9eea90ae88e",
"parentHash":"0xddf9fece0c6dee067a409e73a299bca21cec2d8300dff45739a5b76c680f378d",
"score":"0x20000",
"seal":[

],
Expand Down
2 changes: 1 addition & 1 deletion sync/src/block/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ impl Extension {
match self.header_downloaders.entry(*from) {
Entry::Occupied(mut peer) => {
if !peer.get_mut().update(seq, best_hash) {
cdebug!(SYNC, "Peer #{} status updated but score is less than before", from);
cdebug!(SYNC, "Peer #{} status updated but seqeunce is less than before", from);
return
}
}
Expand Down
13 changes: 2 additions & 11 deletions test/src/e2e.long/invalidBlockPropagation.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ async function setup(): Promise<[Header, Block, Header]> {
new H256(block0.transactionsRoot),
new H256(block0.nextValidatorSetHash),
new H256(block0.stateRoot),
new U256(`${block0.score}`),
block0.seal
);
const author1 = Address.fromString(block1.author);
Expand All @@ -71,7 +70,6 @@ async function setup(): Promise<[Header, Block, Header]> {
new H256(block1.transactionsRoot),
new H256(block1.nextValidatorSetHash),
new H256(block1.stateRoot),
new U256(2222222222222),
block1.seal
);
const author3 = Address.fromString(block0.author);
Expand All @@ -84,7 +82,6 @@ async function setup(): Promise<[Header, Block, Header]> {
new H256(block2.transactionsRoot),
new H256(block2.nextValidatorSetHash),
new H256(block2.stateRoot),
new U256(33333333333333),
block2.seal
);
return [header0, block1, header2];
Expand Down Expand Up @@ -120,14 +117,12 @@ async function testBody(
ttransactionRoot?: H256;
tstateRoot?: H256;
tnextValidatorSetHash?: H256;
tscore?: U256;
tseal?: number[][];
}
) {
const {
tnumber,
textraData,
tscore,
tparent,
tauthor,
ttransactionRoot,
Expand All @@ -137,7 +132,6 @@ async function testBody(
} = params;

const bestHash = header2.hashing();
const bestScore = header2.getScore();

const author4 = Address.fromString(block1.author);
const header = new Header(
Expand All @@ -149,7 +143,6 @@ async function testBody(
new H256(block1.transactionsRoot),
new H256(block1.nextValidatorSetHash),
new H256(block1.stateRoot),
new U256(2222222222222),
block1.seal
);

Expand All @@ -174,15 +167,13 @@ async function testBody(
if (tnextValidatorSetHash != null) {
header.setNextValidatorSetHash(tnextValidatorSetHash);
}
if (tscore != null) {
header.setScore(tscore);
}
if (tseal != null) {
header.setSeal(tseal);
}

const genesis = mock.genesisHash;
await mock.sendStatus(bestScore, bestHash, genesis);
const seq = new U256(0);
await mock.sendStatus(seq, bestHash, genesis);
await mock.sendBlockHeaderResponse([
header0.toEncodeObject(),
header.toEncodeObject(),
Expand Down
25 changes: 0 additions & 25 deletions test/src/e2e.long/invalidBlockPropagation8.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/src/e2e.long/invalidBlockPropagation9.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ const INVALID_SEAL = [Buffer.from("DEADBEEF")];
const params = {
tseal: INVALID_SEAL
};
createTestSuite(9, "OnChain invalid score seal propagation test", params);
createTestSuite(9, "OnChain invalid seal propagation test", params);
6 changes: 1 addition & 5 deletions test/src/e2e.long/onChainBlockValid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ describe("Test onChain block communication", async function() {
new H256(genesisBlock.transactionsRoot),
new H256(genesisBlock.stateRoot),
new H256(genesisBlock.nextValidatorSetHash),
new U256(`${genesisBlock.score}`),
genesisBlock.seal
);
const author2PlatformAddr = Address.fromString(block1.author);
Expand All @@ -89,7 +88,6 @@ describe("Test onChain block communication", async function() {
new H256(block1.transactionsRoot),
new H256(block1.stateRoot),
new H256(block1.nextValidatorSetHash),
new U256(2222222222222),
block1.seal
);
const author3PlatformAddr = Address.fromString(block2.author);
Expand All @@ -102,7 +100,6 @@ describe("Test onChain block communication", async function() {
new H256(block2.transactionsRoot),
new H256(block2.stateRoot),
new H256(block2.nextValidatorSetHash),
new U256(33333333333333),
block2.seal
);

Expand Down Expand Up @@ -137,8 +134,7 @@ describe("Test onChain block communication", async function() {
header2.toEncodeObject()
],
[[], []],
header2.hashing(),
header2.getScore()
header2.hashing()
);

await mock.waitStatusMessage();
Expand Down
10 changes: 4 additions & 6 deletions test/src/helper/mock/blockSyncMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type BlockSyncMessageBody = IStatus | IRequest | IResponse;

interface IStatus {
type: "status";
totalScore: U256;
seq: U256;
bestHash: H256;
genesisHash: H256;
}
Expand All @@ -64,14 +64,12 @@ export class BlockSyncMessage {
if (msgId === MessageType.MESSAGE_ID_STATUS) {
Emitter.emit("status");
const msg = decodedmsg[1];
const totalScore = new U256(
parseInt(msg[0].toString("hex"), 16) || 0
);
const seq = new U256(parseInt(msg[0].toString("hex"), 16) || 0);
const bestHash = new H256(msg[1].toString("hex"));
const genesisHash = new H256(msg[2].toString("hex"));
return new BlockSyncMessage({
type: "status",
totalScore,
seq,
bestHash,
genesisHash
});
Expand Down Expand Up @@ -123,7 +121,7 @@ export class BlockSyncMessage {
return [
MessageType.MESSAGE_ID_STATUS,
[
this.body.totalScore.toEncodeObject(),
this.body.seq.toEncodeObject(),
this.body.bestHash.toEncodeObject(),
this.body.genesisHash.toEncodeObject()
]
Expand Down
Loading