Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: nicol-ii <[email protected]>
  • Loading branch information
nicol-ii committed Sep 23, 2024
1 parent 3769a84 commit f28932a
Show file tree
Hide file tree
Showing 24 changed files with 175 additions and 67 deletions.
Binary file modified runtime_locking_shard0_raft_config_0.dat
Binary file not shown.
Binary file removed runtime_locking_shard0_raft_log_0/000271.ldb
Binary file not shown.
Binary file removed runtime_locking_shard0_raft_log_0/000272.ldb
Binary file not shown.
Binary file removed runtime_locking_shard0_raft_log_0/000274.ldb
Binary file not shown.
Binary file removed runtime_locking_shard0_raft_log_0/000276.ldb
Binary file not shown.
Binary file removed runtime_locking_shard0_raft_log_0/000277.ldb
Binary file not shown.
2 changes: 1 addition & 1 deletion runtime_locking_shard0_raft_log_0/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000273
MANIFEST-000348
26 changes: 13 additions & 13 deletions runtime_locking_shard0_raft_log_0/LOG
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
2024/09/09-15:50:05.394533 281473547685920 Recovering log #270
2024/09/09-15:50:05.394777 281473547685920 Level-0 table #274: started
2024/09/09-15:50:05.398802 281473547685920 Level-0 table #274: 258 bytes OK
2024/09/09-15:50:05.406166 281473547685920 Delete type=2 #269
2024/09/09-15:50:05.406193 281473547685920 Delete type=3 #268
2024/09/09-15:50:05.406203 281473547685920 Delete type=2 #266
2024/09/09-15:50:05.406209 281473547685920 Delete type=0 #270
2024/09/09-15:50:05.406216 281473547685920 Delete type=2 #267
2024/09/09-15:50:08.816117 281473489694080 Compacting 1@0 + 2@1 files
2024/09/09-15:50:08.941789 281473489694080 Generated table #276@0: 23553 keys, 2112743 bytes
2024/09/09-15:50:09.010187 281473489694080 Generated table #277@0: 15014 keys, 1426154 bytes
2024/09/09-15:50:09.010215 281473489694080 Compacted 1@0 + 2@1 files => 3538897 bytes
2024/09/09-15:50:09.011569 281473489694080 compacted to: files[ 0 2 0 0 0 0 0 ]
2024/09/18-14:50:36.677857 281473397743648 Recovering log #345
2024/09/18-14:50:36.678104 281473397743648 Level-0 table #349: started
2024/09/18-14:50:36.682243 281473397743648 Level-0 table #349: 9431 bytes OK
2024/09/18-14:50:36.688393 281473397743648 Delete type=2 #344
2024/09/18-14:50:36.688416 281473397743648 Delete type=3 #343
2024/09/18-14:50:36.688428 281473397743648 Delete type=2 #341
2024/09/18-14:50:36.688436 281473397743648 Delete type=0 #345
2024/09/18-14:50:36.688445 281473397743648 Delete type=2 #342
2024/09/18-14:50:39.405998 281473336601984 Compacting 1@0 + 2@1 files
2024/09/18-14:50:39.530691 281473336601984 Generated table #351@0: 23553 keys, 2112743 bytes
2024/09/18-14:50:39.606386 281473336601984 Generated table #352@0: 16361 keys, 1736226 bytes
2024/09/18-14:50:39.606411 281473336601984 Compacted 1@0 + 2@1 files => 3848969 bytes
2024/09/18-14:50:39.608062 281473336601984 compacted to: files[ 0 2 0 0 0 0 0 ]
23 changes: 13 additions & 10 deletions runtime_locking_shard0_raft_log_0/LOG.old
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
2024/09/09-15:46:15.402807 281473024643104 Recovering log #265
2024/09/09-15:46:15.402963 281473024643104 Level-0 table #269: started
2024/09/09-15:46:15.407154 281473024643104 Level-0 table #269: 258 bytes OK
2024/09/09-15:46:15.412586 281473024643104 Delete type=3 #263
2024/09/09-15:46:15.412602 281473024643104 Delete type=0 #265
2024/09/09-15:46:18.985312 281472896331136 Compacting 1@0 + 2@1 files
2024/09/09-15:46:19.166694 281472896331136 Generated table #271@0: 23553 keys, 2112743 bytes
2024/09/09-15:46:19.278805 281472896331136 Generated table #272@0: 15012 keys, 1426043 bytes
2024/09/09-15:46:19.278849 281472896331136 Compacted 1@0 + 2@1 files => 3538786 bytes
2024/09/09-15:46:19.280751 281472896331136 compacted to: files[ 0 2 0 0 0 0 0 ]
2024/09/18-14:39:03.603927 281473764130848 Recovering log #340
2024/09/18-14:39:03.606058 281473764130848 Level-0 table #344: started
2024/09/18-14:39:03.611033 281473764130848 Level-0 table #344: 38183 bytes OK
2024/09/18-14:39:03.617301 281473764130848 Delete type=0 #340
2024/09/18-14:39:03.617325 281473764130848 Delete type=2 #336
2024/09/18-14:39:03.617336 281473764130848 Delete type=3 #338
2024/09/18-14:39:03.617345 281473764130848 Delete type=2 #339
2024/09/18-14:39:03.617356 281473764130848 Delete type=2 #337
2024/09/18-14:39:06.001298 281473500310912 Compacting 1@0 + 2@1 files
2024/09/18-14:39:06.183053 281473500310912 Generated table #346@0: 23553 keys, 2112743 bytes
2024/09/18-14:39:06.306780 281473500310912 Generated table #347@0: 16321 keys, 1726935 bytes
2024/09/18-14:39:06.306815 281473500310912 Compacted 1@0 + 2@1 files => 3839678 bytes
2024/09/18-14:39:06.310124 281473500310912 compacted to: files[ 0 2 0 0 0 0 0 ]
Binary file removed runtime_locking_shard0_raft_log_0/MANIFEST-000273
Binary file not shown.
Binary file modified runtime_locking_shard0_raft_state_0.dat
Binary file not shown.
5 changes: 5 additions & 0 deletions scripts/gen_bytecode.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
function gen_bytecode()
pay_contract = function(param)
from, to, value, sequence, sig = string.unpack("c32 c32 I8 I8 c64", param)
print(from)
print(to)
print(value)
print(sequence)
print(sig)

function get_account_key(name)
return "account_" .. name
Expand Down
131 changes: 112 additions & 19 deletions scripts/rc.lua
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
function gen_rc()
function trylock(k)
return coroutine.yield(k)
end
function hook()
error("too many instructions")
end
function R(C,payload) -- condense
debug.sethook(hook, "", 1000) -- instruction limit, can only have 1000 instructions
update_map = {}

function R(param)
function trylock(k)
return coroutine.yield(k)
end

function hook()
error("too many instructions")
end

C, payload = string.unpack("c11 c144", param) -- what format is payload in???

-- let each individual contract handle signature and sequences (?)
-- q: should I do check_sig in root contract or allow user-deployed contracts to enforce that...

--debug.sethook(hook, "", 1000) -- instruction limit, should figure out how much set for root contract
pre_update_map = {}

function subroutine(C,payload) -- update the map
function new_trylock(k)
-- make it so it updates from update map
if update_map[C] and update_map[C][k] then -- if value already in map
return update_map[C][k]
end
return trylock("storage_" .. C .. "_" .. k) -- if not already in map
--[[ if pre_update_map[C] and pre_update_map[C][k] then -- if value already in map
return pre_update_map[C][k]
end ]]
return trylock(k)
--return trylock("storage_" .. C .. "_" .. k) -- if not already in map
end

local update;
-- sandbox
do
local f = assert(load(trylock("contract_" .. C)))
-- local f = assert(load(trylock("contract_" .. C)))
local f = assert(load(trylock(C)))
local _ENV = { trylock=new_trylock, subroutine=subroutine,
debug=debug,
table=table, print=print, error=error, pairs=pairs }
Expand All @@ -32,23 +41,107 @@ function gen_rc()
end
-- update final map
for k, v in pairs(update) do
update_map["storage_" .. C .. "_" .. k] = v
if not pre_update_map[C] then
pre_update_map[C] = {}
end
pre_update_map[C][k] = v
end
end
subroutine(C, payload)
debug.sethook()
--debug.sethook()
update_map = {}
for C, tab in pairs(pre_update_map) do
for k, v in pairs(tab) do
update_map["storage_" .. C .. "_" .. k] = v
end
end
return update_map
end

c = string.dump(R, true)
t = {}
for i = 1, #c do
t[#t + 1] = string.format("%02x", string.byte(c, i))
end

return table.concat(t)

end









-- TESTING --

function R1(C,payload) -- original version
function trylock(k)
return test_db[k]
end

function hook()
error("too many instructions")
end

debug.sethook(hook, "", 1000) -- instruction limit, can only have 1000 instructions
pre_update_map = {}

function subroutine(C,payload) -- update the map
function new_trylock(k)
if pre_update_map[C] and pre_update_map[C][k] then -- if value already in map
return pre_update_map[C][k]
end
return trylock("storage_" .. C .. "_" .. k) -- if not already in map
end

local update;
-- sandbox
do
local f = assert(load(trylock("contract_" .. C)))
local _ENV = { trylock=new_trylock, subroutine=subroutine,
debug=debug,
table=table, print=print, error=error, pairs=pairs }
debug.setupvalue(f, 1, _ENV)
f()
_ENV.debug = nil
update = contract(payload)
end
-- update final map
for k, v in pairs(update) do
if not pre_update_map[C] then
pre_update_map[C] = {}
end
pre_update_map[C][k] = v
end
end
subroutine(C, payload)
debug.sethook()
update_map = {}
for C, tab in pairs(pre_update_map) do
for k, v in pairs(tab) do
update_map["storage_" .. C .. "_" .. k] = v
end
end
return update_map
end

contract_USD = io.open("./contracts/contract_USD.lua","rb"):read "*a"
contract_CAD = io.open("./contracts/contract_CAD.lua","rb"):read "*a"
contract_swap = io.open("./contracts/contract_swap.lua","rb"):read "*a"

test_db = {["storage_USD_Alice"]=1000, ["storage_CAD_Alice"]=0,
["storage_USD_Bob"]=0, ["storage_CAD_Bob"]=1000,
["contract_USD"]=contract_USD,
["contract_CAD"]=contract_CAD,
["contract_swap"]=contract_swap,
}
update = R1("swap", {"Alice", "Bob", 10, 11, "USD", "CAD"})
for k,tab in pairs(update) do
print(k .. " " .. tab)
end



Expand Down
2 changes: 2 additions & 0 deletions scripts/secp256k1_ex.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- allows usage of secp256 directly in lua

local ffi = require("ffi")

ffi.cdef[[
Expand Down
1 change: 1 addition & 0 deletions src/parsec/agent/runners/lua/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ namespace cbdc::parsec::agent::runner {
return;
}
auto key_buf = get_stack_string(-1);
m_log->trace("key_buffer", key_buf.value().to_hex());
if(!key_buf.has_value()) {
m_log->error("Contract did not yield a string");
m_result_callback(error_code::yield_type);
Expand Down
1 change: 1 addition & 0 deletions src/parsec/broker/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace cbdc::parsec::broker {
k_it->second.m_value = v;

m_log->trace(this, "Broker locked key for", ticket_number);
m_log->trace(this, "Broker locked key: ", key.to_hex());

return v;
},
Expand Down
Binary file modified ticket_machine_raft_config_0.dat
Binary file not shown.
Binary file removed ticket_machine_raft_log_0/000210.ldb
Binary file not shown.
2 changes: 1 addition & 1 deletion ticket_machine_raft_log_0/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000207
MANIFEST-000267
22 changes: 11 additions & 11 deletions ticket_machine_raft_log_0/LOG
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
2024/09/09-15:50:10.417736 281473057419296 Recovering log #205
2024/09/09-15:50:10.417821 281473057419296 Level-0 table #208: started
2024/09/09-15:50:10.421095 281473057419296 Level-0 table #208: 229 bytes OK
2024/09/09-15:50:10.425855 281473057419296 Delete type=3 #203
2024/09/09-15:50:10.425869 281473057419296 Delete type=0 #205
2024/09/09-15:50:10.860957 281473001778560 Compacting 1@0 + 1@1 files
2024/09/09-15:50:10.865950 281473001778560 Generated table #210@0: 103 keys, 6545 bytes
2024/09/09-15:50:10.865971 281473001778560 Compacted 1@0 + 1@1 files => 6545 bytes
2024/09/09-15:50:10.867991 281473001778560 compacted to: files[ 0 1 0 0 0 0 0 ]
2024/09/09-15:50:10.868077 281473001778560 Delete type=2 #208
2024/09/09-15:50:10.868095 281473001778560 Delete type=2 #206
2024/09/18-14:50:41.694797 281473043312672 Recovering log #265
2024/09/18-14:50:41.694861 281473043312672 Level-0 table #268: started
2024/09/18-14:50:41.698349 281473043312672 Level-0 table #268: 303 bytes OK
2024/09/18-14:50:41.703995 281473043312672 Delete type=3 #263
2024/09/18-14:50:41.704100 281473043312672 Delete type=0 #265
2024/09/18-14:50:42.219986 281472987360640 Compacting 1@0 + 1@1 files
2024/09/18-14:50:42.222405 281472987360640 Generated table #270@0: 163 keys, 9492 bytes
2024/09/18-14:50:42.222430 281472987360640 Compacted 1@0 + 1@1 files => 9492 bytes
2024/09/18-14:50:42.225704 281472987360640 compacted to: files[ 0 1 0 0 0 0 0 ]
2024/09/18-14:50:42.225771 281472987360640 Delete type=2 #268
2024/09/18-14:50:42.225787 281472987360640 Delete type=2 #266
22 changes: 11 additions & 11 deletions ticket_machine_raft_log_0/LOG.old
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
2024/09/09-15:46:21.423529 281473200594976 Recovering log #201
2024/09/09-15:46:21.423614 281473200594976 Level-0 table #204: started
2024/09/09-15:46:21.427908 281473200594976 Level-0 table #204: 229 bytes OK
2024/09/09-15:46:21.436666 281473200594976 Delete type=0 #201
2024/09/09-15:46:21.436689 281473200594976 Delete type=3 #199
2024/09/09-15:46:21.883453 281473144974720 Compacting 1@0 + 1@1 files
2024/09/09-15:46:21.886844 281473144974720 Generated table #206@0: 102 keys, 6463 bytes
2024/09/09-15:46:21.886861 281473144974720 Compacted 1@0 + 1@1 files => 6463 bytes
2024/09/09-15:46:21.890032 281473144974720 compacted to: files[ 0 1 0 0 0 0 0 ]
2024/09/09-15:46:21.890107 281473144974720 Delete type=2 #202
2024/09/09-15:46:21.890124 281473144974720 Delete type=2 #204
2024/09/18-14:39:08.626398 281473377435680 Recovering log #261
2024/09/18-14:39:08.627059 281473377435680 Level-0 table #264: started
2024/09/18-14:39:08.693819 281473377435680 Level-0 table #264: 414 bytes OK
2024/09/18-14:39:08.697811 281473377435680 Delete type=3 #259
2024/09/18-14:39:08.697832 281473377435680 Delete type=0 #261
2024/09/18-14:39:09.107597 281473321528704 Compacting 1@0 + 1@1 files
2024/09/18-14:39:09.109533 281473321528704 Generated table #266@0: 160 keys, 9336 bytes
2024/09/18-14:39:09.109573 281473321528704 Compacted 1@0 + 1@1 files => 9336 bytes
2024/09/18-14:39:09.112121 281473321528704 compacted to: files[ 0 1 0 0 0 0 0 ]
2024/09/18-14:39:09.112187 281473321528704 Delete type=2 #264
2024/09/18-14:39:09.112202 281473321528704 Delete type=2 #262
Binary file removed ticket_machine_raft_log_0/MANIFEST-000207
Binary file not shown.
Binary file modified ticket_machine_raft_state_0.dat
Binary file not shown.
5 changes: 4 additions & 1 deletion tools/bench/parsec/lua/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ namespace cbdc::parsec {
nullptr,
nullptr);
params.append(sig.data(), sig.size());
m_log->warn(params.size());
return params;
}

auto account_wallet::execute_params(
cbdc::buffer params,
bool dry_run,
const std::function<void(bool)>& result_callback) -> bool {
auto buf = cbdc::buffer();
buf.append("root", 4);
auto send_success = m_agent->exec(
m_pay_contract_key,
std::move(params),
Expand All @@ -132,4 +135,4 @@ namespace cbdc::parsec {
auto account_wallet::get_balance() const -> uint64_t {
return m_balance;
}
}
}

0 comments on commit f28932a

Please sign in to comment.