-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: runs dry-run only once per contract and block (#778)
- Loading branch information
Showing
5 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule AeMdw.Db.Aex9BalancesCache do | ||
@moduledoc """ | ||
Cache of aex9 balances in order to call the contract a single time for the same block. | ||
""" | ||
alias AeMdw.Node.Db, as: NodeDb | ||
|
||
alias AeMdw.Blocks | ||
alias AeMdw.EtsCache | ||
|
||
@typep balances :: %{{:address, NodeDb.pubkey()} => integer()} | ||
@table :aex9_balances | ||
@expire_minutes 24 * 60 | ||
|
||
@spec init() :: :ok | ||
def init do | ||
EtsCache.new(@table, @expire_minutes, :ordered_set) | ||
:ok | ||
end | ||
|
||
@spec get(NodeDb.pubkey(), Blocks.block_index(), Blocks.block_hash()) :: | ||
{:ok, balances()} | :not_found | ||
def get(contract_pk, block_index, block_hash) do | ||
case EtsCache.get(@table, {contract_pk, block_index, block_hash}) do | ||
{balances, _time} -> {:ok, balances} | ||
nil -> :not_found | ||
end | ||
end | ||
|
||
@spec put(NodeDb.pubkey(), Blocks.block_index(), Blocks.block_hash(), balances()) :: :ok | ||
def put(contract_pk, height, block_hash, balances) do | ||
EtsCache.put(@table, {contract_pk, height, block_hash}, balances) | ||
:ok | ||
end | ||
|
||
@spec purge(NodeDb.pubkey(), Blocks.block_index()) :: :ok | ||
def purge(contract_pk, block_index) do | ||
with {^contract_pk, ^block_index, hash} <- | ||
EtsCache.next(@table, {contract_pk, block_index, <<>>}) do | ||
EtsCache.del(@table, {contract_pk, block_index, hash}) | ||
end | ||
|
||
:ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters