Skip to content

Commit e041229

Browse files
committed
new receipt format for RPC at epoch 435
1 parent d2bf5ef commit e041229

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

ex/lib/api/db_chain.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ defmodule DB.Chain do
5454
entry_bytes = RocksDB.get(map.entry_hash, db_handle(db_opts, :entry, %{}))
5555
entry = DB.Entry.by_hash(map.entry_hash, db_opts)
5656
tx_bytes = binary_part(entry_bytes, map.index_start, map.index_size)
57+
receipt = if map[:result] do map[:result] else
58+
r = map.receipt
59+
result = RocksDB.ascii_dump(r.result)
60+
logs = Enum.map(r.logs, & RocksDB.ascii_dump(&1))
61+
Map.merge(r, %{result: result, logs: logs})
62+
end
5763
TX.unpack(tx_bytes)
58-
|> Map.put(:result, map[:result])
64+
|> Map.put(:result, receipt)
65+
|> Map.put(:receipt, receipt)
5966
|> Map.put(:metadata, %{entry_hash: map.entry_hash, entry_height: entry.header.height, entry_slot: entry.header.slot})
6067
end
6168
end

ex/lib/api/db_entry.ex

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule DB.Entry do
8888
db_opts[:rtx_commit] && RocksDB.transaction_commit(db_opts.rtx)
8989
end
9090

91-
def apply_into_main_chain(entry, muts_hash, muts_rev, receipts, root_receipts, root_contractstate, db_opts = %{rtx: _}) do
91+
def apply_into_main_chain(entry, muts_hash, muts_rev, {logs, receipts}, root_receipts, root_contractstate, db_opts = %{rtx: _}) do
9292
entry_packed = Entry.pack_for_db(entry)
9393
RocksDB.put(entry.hash, entry_packed, db_handle(db_opts, :entry, %{}))
9494
RocksDB.put("by_height:#{pad_integer(entry.header.height)}:#{entry.hash}", entry.hash, db_handle(db_opts, :entry_meta, %{}))
@@ -102,21 +102,41 @@ defmodule DB.Entry do
102102
RocksDB.put("entry:#{entry.hash}:root_receipts", root_receipts, db_handle(db_opts, :entry_meta, %{}))
103103
RocksDB.put("entry:#{entry.hash}:root_contractstate", root_contractstate, db_handle(db_opts, :entry_meta, %{}))
104104

105-
Enum.each(Enum.zip(entry.txs, receipts), fn({txu, result})->
106-
case :binary.match(entry_packed, TX.pack(txu)) do
107-
{index_start, index_size} ->
108-
tx_ptr = %{entry_hash: entry.hash, result: result, index_start: index_start, index_size: index_size}
109-
|> RDB.vecpak_encode()
110-
RocksDB.put(txu.hash, tx_ptr, db_handle(db_opts, :tx, %{}))
111-
112-
nonce_padded = pad_integer_20(txu.tx.nonce)
113-
RocksDB.put("#{txu.tx.signer}:#{nonce_padded}", txu.hash, db_handle(db_opts, :tx_account_nonce, %{}))
114-
TX.known_receivers(txu)
115-
|> Enum.each(fn(receiver)->
116-
RocksDB.put("#{receiver}:#{nonce_padded}", txu.hash, db_handle(db_opts, :tx_receiver_nonce, %{}))
117-
end)
118-
end
119-
end)
105+
if entry.header.height >= RDBProtocol.forkheight() do
106+
receipts_by_txid = Map.new(receipts, fn r -> {r.txid, Map.drop(r, [:txid])} end)
107+
Enum.each(entry.txs, fn(txu)->
108+
receipt = Map.fetch!(receipts_by_txid, txu.hash)
109+
case :binary.match(entry_packed, TX.pack(txu)) do
110+
{index_start, index_size} ->
111+
tx_ptr = %{entry_hash: entry.hash, receipt: receipt, index_start: index_start, index_size: index_size}
112+
|> RDB.vecpak_encode()
113+
RocksDB.put(txu.hash, tx_ptr, db_handle(db_opts, :tx, %{}))
114+
115+
nonce_padded = pad_integer_20(txu.tx.nonce)
116+
RocksDB.put("#{txu.tx.signer}:#{nonce_padded}", txu.hash, db_handle(db_opts, :tx_account_nonce, %{}))
117+
TX.known_receivers(txu)
118+
|> Enum.each(fn(receiver)->
119+
RocksDB.put("#{receiver}:#{nonce_padded}", txu.hash, db_handle(db_opts, :tx_receiver_nonce, %{}))
120+
end)
121+
end
122+
end)
123+
else
124+
Enum.each(Enum.zip(entry.txs, logs), fn({txu, result})->
125+
case :binary.match(entry_packed, TX.pack(txu)) do
126+
{index_start, index_size} ->
127+
tx_ptr = %{entry_hash: entry.hash, result: result, index_start: index_start, index_size: index_size}
128+
|> RDB.vecpak_encode()
129+
RocksDB.put(txu.hash, tx_ptr, db_handle(db_opts, :tx, %{}))
130+
131+
nonce_padded = pad_integer_20(txu.tx.nonce)
132+
RocksDB.put("#{txu.tx.signer}:#{nonce_padded}", txu.hash, db_handle(db_opts, :tx_account_nonce, %{}))
133+
TX.known_receivers(txu)
134+
|> Enum.each(fn(receiver)->
135+
RocksDB.put("#{receiver}:#{nonce_padded}", txu.hash, db_handle(db_opts, :tx_receiver_nonce, %{}))
136+
end)
137+
end
138+
end)
139+
end
120140
end
121141

122142
def apply_into_main_chain_muts(hash, muts, db_opts = %{rtx: _}) do

ex/lib/consensus/fabric_gen.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ defmodule FabricGen do
347347

348348
RocksDB.put("temporal_tip", next_entry.hash, %{rtx: rtx, cf: cf.sysconf})
349349

350-
DB.Entry.apply_into_main_chain(next_entry, mutations_hash, m_rev, l, root_receipts, root_contractstate, %{rtx: rtx})
350+
DB.Entry.apply_into_main_chain(next_entry, mutations_hash, m_rev, {l, receipts}, root_receipts, root_contractstate, %{rtx: rtx})
351351
if Application.fetch_env!(:ama, :archival_node) do
352352
DB.Entry.apply_into_main_chain_muts(next_entry.hash, m, %{rtx: rtx})
353353
end

ex/native/rdb/src/consensus/bic/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::consensus::bic::coin;
22
use crate::consensus::consensus_kv;
33

4-
pub const FORKHEIGHT: u64 = 434_00000;
4+
pub const FORKHEIGHT: u64 = 435_00000;
55
//pub const FORKHEIGHT: u64 = 0;
66

77
pub const AMA_1_DOLLAR: i128 = 1_000_000_000;

0 commit comments

Comments
 (0)