[cita chain] be consistent with privious logic
@@ -519,18 +519,25 @@ impl Chain {
.collect()
};
- // Save blocks blooms
- for (k, v) in blocks_blooms.iter() {
+ // Save hash -> receipts
+ if !info.get_receipts().is_empty() {
+ let receipts: Vec<Receipt> = info
+ .get_receipts()
+ .iter()
+ .map(|r| Receipt::from(r.get_receipt().clone()))
+ .collect();
+ let block_receipts = BlockReceipts::new(receipts);
let _ = self.db.insert(
Some(cita_db::DataCategory::Extra),
- (k as &DBIndex<LogBloomGroup, Item = LogGroupKey>)
+ (&header_hash as &DBIndex<BlockReceipts, Item = H264>)
.get_index()
.to_vec(),
- rlp::encode(v).into_vec(),
+ rlp::encode(&block_receipts).into_vec(),
);
}
// Save block transaction indexes
+ if !block_transaction_indexes.is_empty() {
for (k, v) in block_transaction_indexes.iter() {
let _ = self.db.insert(
Some(cita_db::DataCategory::Extra),
@@ -540,22 +547,6 @@ impl Chain {
rlp::encode(v).into_vec(),
);
}
-
- // Save hash -> receipts
- if !info.get_receipts().is_empty() {
- let receipts: Vec<Receipt> = info
- .get_receipts()
- .iter()
- .map(|r| Receipt::from(r.get_receipt().clone()))
- .collect();
- let block_receipts = BlockReceipts::new(receipts);
- let _ = self.db.insert(
- Some(cita_db::DataCategory::Extra),
- (&header_hash as &DBIndex<BlockReceipts, Item = H264>)
- .get_index()
- .to_vec(),
- rlp::encode(&block_receipts).into_vec(),
- );
}
// Save number -> header
@@ -568,6 +559,18 @@ impl Chain {
rlp::encode(&header).into_vec(),
);
+ // Save Body
+ let mheight = self.get_max_store_height();
+ if mheight < number || (number == 0 && mheight == 0) {
+ let _ = self.db.insert(
+ Some(cita_db::DataCategory::Bodies),
+ (&number as &DBIndex<BlockBody, Item = BlockNumberKeyLong>)
+ .get_index()
+ .to_vec(),
+ rlp::encode(block.body()).into_vec(),
+ );
+ }
+
// Save hash -> blockNumber
let _ = self.db.insert(
Some(cita_db::DataCategory::Extra),
@@ -577,15 +580,14 @@ impl Chain {
rlp::encode(&number).into_vec(),
);
- // Save Body
- let mheight = self.get_max_store_height();
- if mheight < number || (number == 0 && mheight == 0) {
+ // Save blocks blooms
+ for (k, v) in blocks_blooms.iter() {
let _ = self.db.insert(
- Some(cita_db::DataCategory::Bodies),
- (&number as &DBIndex<BlockBody, Item = BlockNumberKeyLong>)
+ Some(cita_db::DataCategory::Extra),
+ (k as &DBIndex<LogBloomGroup, Item = LogGroupKey>)
.get_index()
.to_vec(),
- rlp::encode(block.body()).into_vec(),
+ rlp::encode(v).into_vec(),
);
}
