Skip to content

Commit 791f0f6

Browse files
committed
full migration plus purge EETF
1 parent 304dffe commit 791f0f6

File tree

20 files changed

+118
-315
lines changed

20 files changed

+118
-315
lines changed

ex/build_clean.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
#&& export ERL_COMPILER_OPTIONS=bin_opt_info \
4+
5+
podman run -it --rm -v ../.:/root/node --entrypoint bash erlang_builder -c "echo 'building amadeus..' \
6+
&& cd /tmp \
7+
&& git clone https://github.com/amadeusprotocol/node \
8+
&& cd /tmp/node/ex \
9+
&& export MIX_ENV=prod \
10+
&& export CC='clang-19' CXX='clang++-19' CFLAGS='-march=haswell' CXXFLAGS='-march=haswell' \
11+
&& export RUSTFLAGS='-C target-cpu=haswell -C opt-level=3' \
12+
&& export LLVM_CONFIG_PATH=/usr/bin/llvm-config-19 LIBCLANG_PATH=/usr/lib/llvm-19/lib \
13+
&& mix deps.get \
14+
&& mix release \
15+
&& cp _build/prod/rel/bakeware/ama /root/node/ex/amadeusd"
16+
sha256sum amadeusd

ex/lib/api/api_chain.ex

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,6 @@ defmodule API.Chain do
100100
last_100/50
101101
end
102102

103-
def count_wallets() do
104-
key = "account:#{:binary.copy(<<0>>, 48)}:balance:AMA"
105-
count_wallets_1(key, 0)
106-
end
107-
def count_wallets_1(key, acc) do
108-
%{db: db, cf: cf} = :persistent_term.get({:rocksdb, Fabric})
109-
seek = RocksDB.seek_next(key, %{db: db, cf: cf.contractstate})
110-
case seek do
111-
{<<"account:", pk::384, ":balance:AMA">>, _} ->
112-
key = <<"account:", (pk+1)::384, ":balance:AMA">>
113-
count_wallets_1(key, acc + 1)
114-
{<<"account:", pk::384, _::binary>>, _} ->
115-
key = <<"account:", pk::384, ":balance:AMA">>
116-
count_wallets_1(key, acc)
117-
{_, _} -> acc
118-
end
119-
end
120-
121103
def format_entry_for_client(nil) do nil end
122104
def format_entry_for_client(entry) do
123105
hash = entry.hash

ex/lib/api/api_contract.ex

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,27 @@ defmodule API.Contract do
2929
end
3030

3131
def richlist() do
32-
%{db: db, cf: cf} = :persistent_term.get({:rocksdb, Fabric})
33-
opts = %{db: db, cf: cf.contractstate, to_integer: true}
34-
RocksDB.get_prefix("bic:coin:balance:", opts)
35-
|> Enum.map(fn({pk_symbol, coins})->
36-
<<pk::48-binary,":",symbol::binary>> = pk_symbol
37-
%{pk: Base58.encode(pk), symbol: symbol, flat: coins, float: trunc(BIC.Coin.from_flat(coins))}
38-
end)
32+
key = "account:#{:binary.copy(<<0>>, 48)}:balance:AMA"
33+
{acc, count} = richlist_1(key, {[], 0})
34+
acc = acc
3935
|> Enum.filter(& &1.symbol == "AMA")
4036
|> Enum.sort_by(& &1.flat, :desc)
37+
{acc, count}
38+
end
39+
def richlist_1(key, {acc, count}) do
40+
%{db: db, cf: cf} = :persistent_term.get({:rocksdb, Fabric})
41+
seek = RocksDB.seek_next(key, %{db: db, cf: cf.contractstate})
42+
case seek do
43+
{<<"account:", pk::384, ":balance:AMA">>, value} ->
44+
key = <<"account:", (pk+1)::384, ":balance:AMA">>
45+
flat = :erlang.binary_to_integer(value)
46+
entry = %{pk: Base58.encode(<<pk::384>>), symbol: "AMA", flat: flat, float: trunc(BIC.Coin.from_flat(flat))}
47+
richlist_1(key, {acc ++ [entry], count + 1})
48+
{<<"account:", pk::384, _::binary>>, _} ->
49+
key = <<"account:", pk::384, ":balance:AMA">>
50+
richlist_1(key, {acc, count})
51+
{_, _} -> {acc, count}
52+
end
4153
end
4254

4355
def total_burned() do

ex/lib/api/api_epoch.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule API.Epoch do
1313

1414
def get_emission_address(pk) do
1515
pk = if byte_size(pk) != 48, do: Base58.decode(pk), else: pk
16-
API.Contract.get("bic:epoch:emission_address:#{pk}")
16+
API.Contract.get("account:#{pk}:attribute:emission_address")
1717
|> case do
1818
nil -> nil
1919
addr -> Base58.encode(addr)

ex/lib/api/api_wallet.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule API.Wallet do
1616

1717
%{db: db, cf: cf} = :persistent_term.get({:rocksdb, Fabric})
1818
opts = %{db: db, cf: cf.contractstate, to_integer: true}
19-
RocksDB.get_prefix("bic:coin:balance:#{pk}:", opts)
19+
RocksDB.get_prefix("account:#{pk}:balance:", opts)
2020
|> Enum.map(fn({symbol, coins})->
2121
%{symbol: symbol, flat: coins, float: BIC.Coin.from_flat(coins)}
2222
end)

ex/lib/api/db_chain.ex

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,15 @@ defmodule DB.Chain do
3636
end
3737

3838
def pop(pk, db_opts \\ %{}) do
39-
RocksDB.get("bic:epoch:pop:#{pk}", db_handle(db_opts, :contractstate, %{}))
39+
RocksDB.get("account:#{pk}:attribute:pop", db_handle(db_opts, :contractstate, %{}))
4040
end
4141

4242
def nonce(pk, db_opts \\ %{}) do
43-
if RocksDB.exists("account:#{pk}:attribute:nonce", db_handle(db_opts, :contractstate, %{to_integer: true})) do
44-
RocksDB.get("account:#{pk}:attribute:nonce", db_handle(db_opts, :contractstate, %{to_integer: true}))
45-
else
46-
RocksDB.get("bic:base:nonce:#{pk}", db_handle(db_opts, :contractstate, %{to_integer: true}))
47-
end
43+
RocksDB.get("account:#{pk}:attribute:nonce", db_handle(db_opts, :contractstate, %{to_integer: true}))
4844
end
4945

5046
def balance(pk, symbol \\ "AMA", db_opts \\ %{}) do
51-
if RocksDB.exists("account:#{pk}:balance:#{symbol}", db_handle(db_opts, :contractstate, %{to_integer: true})) do
52-
RocksDB.get("account:#{pk}:balance:#{symbol}", db_handle(db_opts, :contractstate, %{to_integer: true})) || 0
53-
else
54-
RocksDB.get("bic:coin:balance:#{pk}:#{symbol}", db_handle(db_opts, :contractstate, %{to_integer: true})) || 0
55-
end
47+
RocksDB.get("account:#{pk}:balance:#{symbol}", db_handle(db_opts, :contractstate, %{to_integer: true})) || 0
5648
end
5749

5850
def tx(tx_hash, db_opts \\ %{}) do
@@ -79,23 +71,20 @@ defmodule DB.Chain do
7971
end
8072

8173
def validators_for_height(height, db_opts \\ %{}) do
82-
opts = db_handle(db_opts, :contractstate, %{term: true})
74+
opts = db_handle(db_opts, :contractstate, %{})
8375
cond do
84-
height in 3195570..3195575 ->
85-
RocksDB.get("bic:epoch:validators:height:000000319557", opts)
86-
true ->
87-
case RocksDB.get_prev_or_first("bic:epoch:validators:height:", pad_integer(height), db_handle(db_opts, :contractstate, %{})) do
88-
{nil, nil} ->
89-
{_, value} = RocksDB.get_prev_or_first("bic:epoch:trainers:height:", pad_integer(height), opts)
90-
value
91-
{_, value} -> RDB.vecpak_decode(value)
92-
end
76+
height in 3195570..3195575 ->
77+
RocksDB.get("bic:epoch:validators:height:000000319557", opts)
78+
|> RDB.vecpak_decode()
79+
true ->
80+
{_, value} = RocksDB.get_prev_or_first("bic:epoch:validators:height:", pad_integer(height), opts)
81+
RDB.vecpak_decode(value)
9382
end
9483
end
9584

9685
def validators_last_change_height(height, db_opts \\ %{}) do
97-
opts = db_handle(db_opts, :contractstate, %{term: true})
98-
{key, _value} = RocksDB.get_prev_or_first("bic:epoch:trainers:height:", pad_integer(height), opts)
86+
opts = db_handle(db_opts, :contractstate, %{})
87+
{key, _value} = RocksDB.get_prev_or_first("bic:epoch:validators:height:", pad_integer(height), opts)
9988
:erlang.binary_to_integer(key)
10089
end
10190

ex/lib/bic/base.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ defmodule BIC.Base do
6565

6666
cond do
6767
env.entry_height == 0 ->
68-
kv_put("bic:epoch:trainers:0", [env.entry_signer], %{term: true})
69-
kv_put("bic:epoch:pop:#{env.entry_signer}", EntryGenesis.pop())
68+
kv_put("bic:epoch:validators:height:000000000000", [env.entry_signer], %{term: true})
69+
kv_put("account:#{env.entry_signer}:attribute:pop", EntryGenesis.pop())
7070
rem(env.entry_height, 100_000) == 99_999 ->
7171
BIC.Epoch.next(env)
7272
true -> :ok

ex/lib/consensus/models/entry_genesis.ex

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,14 @@ defmodule EntryGenesis do
187187
RocksDB.put("rooted_tip", entry_signed.hash, %{rtx: rtx, cf: cf.sysconf})
188188

189189
validator_pks = Application.fetch_env!(:ama, :keys) |> Enum.map(& &1.pk)
190-
RocksDB.put("bic:epoch:trainers:0",
191-
:erlang.term_to_binary(validator_pks), %{rtx: rtx, cf: cf.contractstate})
192-
RocksDB.put("bic:epoch:trainers:height:#{String.pad_leading("0", 12, "0")}",
193-
:erlang.term_to_binary(validator_pks), %{rtx: rtx, cf: cf.contractstate})
190+
RocksDB.put("bic:epoch:validators:height:#{String.pad_leading("0", 12, "0")}",
191+
RDB.vecpak_encode(validator_pks), %{rtx: rtx, cf: cf.contractstate})
194192
RocksDB.put("bic:epoch:diff_bits", "8", %{rtx: rtx, cf: cf.contractstate})
195193
RocksDB.put("bic:epoch:segment_vr_hash", Blake3.hash(vr), %{rtx: rtx, cf: cf.contractstate})
196194

197195
Enum.each(Application.fetch_env!(:ama, :keys), fn(key)->
198-
RocksDB.put("bic:coin:balance:#{key.pk}:AMA", "1001000000000", %{rtx: rtx, cf: cf.contractstate})
199-
RocksDB.put("bic:epoch:pop:#{key.pk}", key.pop, %{rtx: rtx, cf: cf.contractstate})
196+
RocksDB.put("account:#{key.pk}:balance:AMA", "1001000000000", %{rtx: rtx, cf: cf.contractstate})
197+
RocksDB.put("account:#{key.pk}:attribute:pop", key.pop, %{rtx: rtx, cf: cf.contractstate})
200198
end)
201199
rtx = RocksDB.transaction_commit(rtx)
202200
end

ex/lib/consensus/models/tx.ex

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,21 @@ defmodule TX do
5656
end
5757
end
5858

59-
def validate(txu, is_special_meeting_block \\ false) do
59+
def validate(txu_orig, is_special_meeting_block \\ false) do
6060
try do
61-
true = !txu[:tx_encoded]
62-
63-
txu = Map.take(txu, @fields)
64-
tx_encoded = RDB.vecpak_encode(txu.tx)
65-
61+
txu = Map.take(txu_orig, @fields)
62+
true = txu == txu_orig
6663
tx = Map.take(txu.tx, @fields_tx)
64+
true = txu.tx == tx
65+
txu = put_in(txu, [:tx], tx)
6766
action = Map.take(txu.tx.action, @fields_action)
67+
true = txu.tx.action == action
68+
txu = put_in(txu, [:tx, :action], action)
6869

70+
tx_encoded = RDB.vecpak_encode(txu.tx)
6971
if byte_size(tx_encoded) >= Application.fetch_env!(:ama, :tx_size), do: throw(%{error: :too_large})
70-
71-
hash = Map.fetch!(txu, :hash)
72-
signature = Map.fetch!(txu, :signature)
73-
74-
if hash != :crypto.hash(:sha256, tx_encoded), do: throw(%{error: :invalid_hash})
75-
if !BlsEx.verify?(txu.tx.signer, signature, hash, BLS12AggSig.dst_tx()), do: throw(%{error: :invalid_signature})
72+
if txu.hash != :crypto.hash(:sha256, tx_encoded), do: throw(%{error: :invalid_hash})
73+
if !BlsEx.verify?(txu.tx.signer, txu.signature, txu.hash, BLS12AggSig.dst_tx()), do: throw(%{error: :invalid_signature})
7674

7775
if !is_integer(txu.tx.nonce), do: throw(%{error: :nonce_not_integer})
7876
if txu.tx.nonce > 99_999_999_999_999_999_999, do: throw(%{error: :nonce_too_high})
@@ -105,7 +103,6 @@ defmodule TX do
105103
#if !!txp.tx[:delay] and txp.tx.delay <= 0, do: throw %{error: :delay_too_low}
106104
#if !!txp.tx[:delay] and txp.tx.delay > 100_000, do: throw %{error: :delay_too_hi}
107105

108-
txu = %{tx: %{nonce: txu.tx.nonce, signer: txu.tx.signer, action: action}, hash: hash, signature: signature}
109106
throw %{error: :ok, txu: txu}
110107
catch
111108
:throw,r -> r

ex/lib/ex.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ defmodule Ama do
5757
def offline_node() do
5858
%{db: db, cf: cf} = :persistent_term.get({:rocksdb, Fabric})
5959
if !DB.Entry.by_hash(EntryGenesis.get().hash) do
60-
RocksDB.put("bic:epoch:trainers:height:#{String.pad_leading("0", 12, "0")}",
61-
:erlang.term_to_binary([EntryGenesis.signer()]), %{db: db, cf: cf.contractstate})
60+
RocksDB.put("bic:epoch:validators:height:#{String.pad_leading("0", 12, "0")}",
61+
RDB.vecpak_encode([EntryGenesis.signer()]), %{db: db, cf: cf.contractstate})
6262

6363
entry = EntryGenesis.get()
6464
DB.Entry.insert(entry)

0 commit comments

Comments
 (0)