Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
18788246
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
18788246
编写于
6月 18, 2017
作者:
D
Daniel Larimer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs and add benchmark code
上级
60a30466
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
87 deletion
+68
-87
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+9
-8
tests/tests/block_tests.cpp
tests/tests/block_tests.cpp
+59
-79
未找到文件。
libraries/chain/wasm_interface.cpp
浏览文件 @
18788246
...
...
@@ -18,7 +18,7 @@ namespace eos { namespace chain {
}
DEFINE_INTRINSIC_FUNCTION4
(
env
,
store
,
store
,
none
,
i32
,
keyptr
,
i32
,
keylen
,
i32
,
valueptr
,
i32
,
valuelen
)
{
ilog
(
"store"
);
// ilog( "store ${keylen} ${vallen}", ("keylen",keylen)("vallen",valuelen)
);
FC_ASSERT
(
keylen
>
0
);
FC_ASSERT
(
valuelen
>=
0
);
...
...
@@ -33,8 +33,8 @@ DEFINE_INTRINSIC_FUNCTION4(env,store,store,none,i32,keyptr,i32,keylen,i32,valuep
char
*
value
=
&
memoryRef
<
char
>
(
mem
,
valueptr
);
string
keystr
(
key
,
key
+
keylen
);
idump
((
keystr
));
if
(
valuelen
==
8
)
idump
((
*
((
int64_t
*
)
value
)));
//
idump((keystr));
//
if( valuelen == 8 ) idump(( *((int64_t*)value)));
const
auto
*
obj
=
db
.
find
<
key_value_object
,
by_scope_key
>
(
boost
::
make_tuple
(
scope
,
keystr
)
);
...
...
@@ -119,6 +119,7 @@ DEFINE_INTRINSIC_FUNCTION2(env,AccountName_unpack,AccountName_unpack,none,i32,st
const
char
*
pos
=
&
memoryRef
<
const
char
>
(
mem
,
stream
[
1
]
);
const
char
*
end
=
&
memoryRef
<
const
char
>
(
mem
,
stream
[
2
]
);
AccountName
*
name
=
&
memoryRef
<
AccountName
>
(
mem
,
accountptr
);
memset
(
name
,
0
,
32
);
fc
::
datastream
<
const
char
*>
ds
(
pos
,
end
-
pos
);
fc
::
raw
::
unpack
(
ds
,
*
name
);
...
...
@@ -129,7 +130,7 @@ DEFINE_INTRINSIC_FUNCTION2(env,AccountName_unpack,AccountName_unpack,none,i32,st
DEFINE_INTRINSIC_FUNCTION4
(
env
,
load
,
load
,
i32
,
i32
,
keyptr
,
i32
,
keylen
,
i32
,
valueptr
,
i32
,
valuelen
)
{
ilog
(
"load"
);
//
ilog( "load" );
FC_ASSERT
(
keylen
>
0
);
FC_ASSERT
(
valuelen
>=
0
);
...
...
@@ -143,14 +144,14 @@ DEFINE_INTRINSIC_FUNCTION4(env,load,load,i32,i32,keyptr,i32,keylen,i32,valueptr,
char
*
key
=
&
memoryRef
<
char
>
(
mem
,
keyptr
);
char
*
value
=
&
memoryRef
<
char
>
(
mem
,
valueptr
);
string
keystr
(
key
,
key
+
keylen
);
idump
((
keystr
));
//
idump((keystr));
const
auto
*
obj
=
db
.
find
<
key_value_object
,
by_scope_key
>
(
boost
::
make_tuple
(
scope
,
keystr
)
);
if
(
obj
==
nullptr
)
return
-
1
;
auto
copylen
=
std
::
min
<
size_t
>
(
obj
->
value
.
size
(),
valuelen
);
if
(
copylen
)
{
memcpy
(
value
,
obj
->
value
.
data
(),
copylen
);
if
(
copylen
==
8
)
idump
((
*
((
int64_t
*
)
value
)));
//
if( copylen == 8 ) idump(( *((int64_t*)value)));
}
return
copylen
;
}
...
...
@@ -278,7 +279,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
std
::
string
mangledapply
(
"onApply_"
);
mangledapply
+=
std
::
string
(
current_validate_context
->
msg
.
type
)
+
"_"
;
mangledapply
+=
std
::
string
(
current_validate_context
->
msg
.
recipient
);
idump
((
mangledapply
));
//
idump((mangledapply));
FunctionInstance
*
apply
=
asFunctionNullable
(
getInstanceExport
(
current_module
,
mangledapply
.
c_str
()));
if
(
!
apply
)
return
;
/// if not found then it is a no-op
...
...
@@ -333,7 +334,7 @@ DEFINE_INTRINSIC_FUNCTION1(env,toUpper,toUpper,none,i32,charptr) {
void
wasm_interface
::
init
(
apply_context
&
c
)
{
try
{
ilog
(
"WASM INTERFACE INIT"
);
//
ilog( "WASM INTERFACE INIT" );
load
(
c
.
scope
,
c
.
db
);
current_validate_context
=
&
c
;
...
...
tests/tests/block_tests.cpp
浏览文件 @
18788246
...
...
@@ -128,7 +128,7 @@ BOOST_FIXTURE_TEST_CASE(create_script, testing_fixture)
/*
auto c_apply = R"(
/// Start the EOS Built
In Library HERE
/// Start the EOS Built
in Library Here
typedef long long uint64_t;
typedef unsigned int uint32_t;
...
...
@@ -242,22 +242,22 @@ void onApply_Transfer_simplecoin() {
static Balance to_balance;
to_balance.balance = 0;
read = load(
(char*)&message.from, sizeof(message.from), (char*)
&from_balance.balance, sizeof(from_balance.balance) );
read = load(
&message.from, sizeof(message.from),
&from_balance.balance, sizeof(from_balance.balance) );
assert( read == sizeof(Balance), "no existing balance" );
assert( from_balance.balance >= message.amount, "insufficient funds" );
read = load(
(char*)&message.to, sizeof(message.to), (char*)&from_balance.balance, sizeof(from
_balance.balance) );
read = load(
&message.to, sizeof(message.to), &to_balance.balance, sizeof(to
_balance.balance) );
to_balance.balance += message.amount;
from_balance.balance -= message.amount;
if( from_balance.balance )
store(
(char*)&message.from, sizeof(message.from), (char*)
&from_balance.balance, sizeof(from_balance.balance) );
store(
&message.from, sizeof(AccountName),
&from_balance.balance, sizeof(from_balance.balance) );
else
remove(
(char*)&message.from, sizeof(message.from
) );
remove(
&message.from, sizeof(AccountName
) );
store(
(char*)&message.to, sizeof(message.to), (char*)
&to_balance.balance, sizeof(to_balance.balance) );
store(
&message.to, sizeof(message.to),
&to_balance.balance, sizeof(to_balance.balance) );
}
)"
;
")
;
*/
std
::
string
wast_apply
=
R"(
...
...
@@ -265,7 +265,6 @@ R"(
(type $FUNCSIG$vii (func (param i32 i32)))
(type $FUNCSIG$viiii (func (param i32 i32 i32 i32)))
(type $FUNCSIG$iii (func (param i32 i32) (result i32)))
(type $FUNCSIG$vj (func (param i64)))
(type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32)))
(type $FUNCSIG$i (func (result i32)))
(type $FUNCSIG$iiii (func (param i32 i32 i32) (result i32)))
...
...
@@ -274,8 +273,6 @@ R"(
(import "env" "assert" (func $assert (param i32 i32)))
(import "env" "load" (func $load (param i32 i32 i32 i32) (result i32)))
(import "env" "memcpy" (func $memcpy (param i32 i32 i32) (result i32)))
(import "env" "print" (func $print (param i32 i32)))
(import "env" "printi64" (func $printi64 (param i64)))
(import "env" "readMessage" (func $readMessage (param i32 i32) (result i32)))
(import "env" "remove" (func $remove (param i32 i32) (result i32)))
(import "env" "store" (func $store (param i32 i32 i32 i32)))
...
...
@@ -285,10 +282,8 @@ R"(
(data (i32.const 8240) "String is longer than account name allows\00")
(data (i32.const 8288) "read past end of stream\00")
(data (i32.const 8368) "simplecoin\00")
(data (i32.const 8384) "onInit simiplecoin\00")
(data (i32.const 8416) "onApply_Transfer_simplecoin\00")
(data (i32.const 8672) "no existing balance\00")
(data (i32.const 8704) "insufficient funds\00")
(data (i32.const 8608) "no existing balance\00")
(data (i32.const 8640) "insufficient funds\00")
(export "memory" (memory $0))
(export "malloc" (func $malloc))
(export "DataStream_init" (func $DataStream_init))
...
...
@@ -636,73 +631,65 @@ R"(
(i32.const 8320)
(i32.const 8)
)
(call $print
(i32.const 8384)
(i32.const 15)
)
)
(func $onApply_Transfer_simplecoin
(local $0 i32)
(local $1 i32)
(local $2 i64)
(call $print
(i32.const 8416)
(i32.const 20)
)
(set_local $0
(call $readMessage
(i32.const 8
448
)
(i32.const 8
384
)
(i32.const 100)
)
)
(i32.store offset=8
632
(i32.store offset=8
568
(i32.const 0)
(i32.const 8
448
)
(i32.const 8
384
)
)
(i32.store offset=8
636
(i32.store offset=8
572
(i32.const 0)
(i32.const 8
448
)
(i32.const 8
384
)
)
(i32.store offset=8
640
(i32.store offset=8
576
(i32.const 0)
(i32.add
(get_local $0)
(i32.const 8
448
)
(i32.const 8
384
)
)
)
(call $AccountName_unpack
(i32.const 8
632
)
(i32.const 8
552
)
(i32.const 8
568
)
(i32.const 8
488
)
)
(call $AccountName_unpack
(i32.const 8
632
)
(i32.const 85
84
)
(i32.const 8
568
)
(i32.const 85
20
)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=8
636
(i32.load offset=8
572
(i32.const 0)
)
(i32.const 8)
)
(i32.load offset=8
640
(i32.load offset=8
576
(i32.const 0)
)
)
(i32.const 8288)
)
(i64.store offset=8
616
(i64.store offset=8
552
(i32.const 0)
(i64.load align=1
(tee_local $0
(i32.load offset=8
636
(i32.load offset=8
572
(i32.const 0)
)
)
)
)
(i32.store offset=8
636
(i32.store offset=8
572
(i32.const 0)
(i32.add
(get_local $0)
...
...
@@ -710,20 +697,20 @@ R"(
)
)
(call $Varint_unpack
(i32.const 8
632
)
(i32.const 8
568
)
(i32.const 8312)
)
(call $assert
(i32.le_u
(i32.add
(i32.load offset=8
636
(i32.load offset=8
572
(i32.const 0)
)
(i32.load offset=8312
(i32.const 0)
)
)
(i32.load offset=8
640
(i32.load offset=8
576
(i32.const 0)
)
)
...
...
@@ -763,7 +750,7 @@ R"(
(get_local $0)
(i32.const 20)
)
(i32.load offset=8
636
(i32.load offset=8
572
(i32.const 0)
)
(i32.load offset=8312
...
...
@@ -771,79 +758,66 @@ R"(
)
)
)
(i32.store offset=8624
(i64.store offset=8592
(i32.const 0)
(i64.const 0)
)
(i32.store offset=8560
(i32.const 0)
(i32.add
(get_local $0)
(i32.const 16)
)
)
(call $print
(i32.const 8552)
(i32.const 32)
)
(call $print
(i32.const 8584)
(i32.const 32)
)
(call $printi64
(i64.load offset=8616
(i32.const 0)
)
)
(i64.store offset=8656
(i32.const 0)
(i64.const 0)
)
(call $assert
(i32.eq
(call $load
(i32.const 8
552
)
(i32.const 8
488
)
(i32.const 32)
(i32.const 8
648
)
(i32.const 8
584
)
(i32.const 8)
)
(i32.const 8)
)
(i32.const 86
72
)
(i32.const 86
08
)
)
(call $assert
(i64.ge_s
(i64.load offset=8
648
(i64.load offset=8
584
(i32.const 0)
)
(i64.load offset=8
616
(i64.load offset=8
552
(i32.const 0)
)
)
(i32.const 8
704
)
(i32.const 8
640
)
)
(drop
(call $load
(i32.const 85
84
)
(i32.const 85
20
)
(i32.const 32)
(i32.const 8
648
)
(i32.const 8
592
)
(i32.const 8)
)
)
(i64.store offset=8
656
(i64.store offset=8
592
(i32.const 0)
(i64.add
(i64.load offset=8
656
(i64.load offset=8
592
(i32.const 0)
)
(tee_local $2
(i64.load offset=8
616
(i64.load offset=8
552
(i32.const 0)
)
)
)
)
(i64.store offset=8
648
(i64.store offset=8
584
(i32.const 0)
(tee_local $2
(i64.sub
(i64.load offset=8
648
(i64.load offset=8
584
(i32.const 0)
)
(get_local $2)
...
...
@@ -858,29 +832,30 @@ R"(
)
)
(call $store
(i32.const 8
552
)
(i32.const 8
488
)
(i32.const 32)
(i32.const 8
648
)
(i32.const 8
584
)
(i32.const 8)
)
(br $label$0)
)
(drop
(call $remove
(i32.const 8
552
)
(i32.const 8
488
)
(i32.const 32)
)
)
)
(call $store
(i32.const 85
84
)
(i32.const 85
20
)
(i32.const 32)
(i32.const 8
656
)
(i32.const 8
592
)
(i32.const 8)
)
)
)
)"
;
types
::
SetCode
handler
;
...
...
@@ -909,14 +884,19 @@ R"(
}
auto
start
=
fc
::
time_point
::
now
();
for
(
uint32_t
i
=
0
;
i
<
1000
;
++
i
)
{
eos
::
chain
::
SignedTransaction
trx
;
trx
.
emplaceMessage
(
"simplecoin"
,
"simplecoin"
,
vector
<
AccountName
>
{
"init1"
},
"Transfer"
,
types
::
Transfer
{
"simplecoin"
,
"init1"
,
1
01
,
"hello"
}
);
types
::
Transfer
{
"simplecoin"
,
"init1"
,
1
+
i
,
"hello"
}
);
trx
.
expiration
=
db
.
head_block_time
()
+
100
;
trx
.
set_reference_block
(
db
.
head_block_id
());
db
.
push_transaction
(
trx
);
}
auto
end
=
fc
::
time_point
::
now
();
idump
((
1000
*
1000000.0
/
(
end
-
start
).
count
()
)
);
{
wlog
(
"transfer 102 from init1 to init2"
);
eos
::
chain
::
SignedTransaction
trx
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录