mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-23 17:51:39 +00:00
cleanup calldepth=0 events logic
This commit is contained in:
@ -230,7 +230,7 @@ func TestWSCallWait(t *testing.T) {
|
|||||||
|
|
||||||
// susbscribe to the new contract
|
// susbscribe to the new contract
|
||||||
amt = uint64(10001)
|
amt = uint64(10001)
|
||||||
eid2 := types.EventStringAccReceive(contractAddr)
|
eid2 := types.EventStringAccOutput(contractAddr)
|
||||||
subscribe(t, con, eid2)
|
subscribe(t, con, eid2)
|
||||||
defer func() {
|
defer func() {
|
||||||
unsubscribe(t, con, eid2)
|
unsubscribe(t, con, eid2)
|
||||||
@ -254,7 +254,7 @@ func TestWSCallNoWait(t *testing.T) {
|
|||||||
|
|
||||||
// susbscribe to the new contract
|
// susbscribe to the new contract
|
||||||
amt = uint64(10001)
|
amt = uint64(10001)
|
||||||
eid := types.EventStringAccReceive(contractAddr)
|
eid := types.EventStringAccOutput(contractAddr)
|
||||||
subscribe(t, con, eid)
|
subscribe(t, con, eid)
|
||||||
defer func() {
|
defer func() {
|
||||||
unsubscribe(t, con, eid)
|
unsubscribe(t, con, eid)
|
||||||
@ -284,16 +284,20 @@ func TestWSCallCall(t *testing.T) {
|
|||||||
// susbscribe to the new contracts
|
// susbscribe to the new contracts
|
||||||
amt = uint64(10001)
|
amt = uint64(10001)
|
||||||
eid1 := types.EventStringAccReceive(contractAddr1)
|
eid1 := types.EventStringAccReceive(contractAddr1)
|
||||||
eid2 := types.EventStringAccReceive(contractAddr2)
|
|
||||||
subscribe(t, con, eid1)
|
subscribe(t, con, eid1)
|
||||||
subscribe(t, con, eid2)
|
|
||||||
defer func() {
|
defer func() {
|
||||||
unsubscribe(t, con, eid1)
|
unsubscribe(t, con, eid1)
|
||||||
unsubscribe(t, con, eid2)
|
|
||||||
con.Close()
|
con.Close()
|
||||||
}()
|
}()
|
||||||
// call contract2, which should call contract1, and wait for ev1
|
// call contract2, which should call contract1, and wait for ev1
|
||||||
data := []byte{0x1} // just needs to be non empty for this to be a CallTx
|
data := []byte{0x1} // just needs to be non empty for this to be a CallTx
|
||||||
|
|
||||||
|
// let the contract get created first
|
||||||
|
waitForEvent(t, con, eid1, true, func() {
|
||||||
|
}, func(eid string, b []byte) error {
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
// call it
|
||||||
waitForEvent(t, con, eid1, true, func() {
|
waitForEvent(t, con, eid1, true, func() {
|
||||||
tx, _ := broadcastTx(t, "JSONRPC", userByteAddr, contractAddr2, data, userBytePriv, amt, 1000, 1000)
|
tx, _ := broadcastTx(t, "JSONRPC", userByteAddr, contractAddr2, data, userBytePriv, amt, 1000, 1000)
|
||||||
*txid = account.HashSignBytes(tx)
|
*txid = account.HashSignBytes(tx)
|
||||||
|
@ -130,7 +130,6 @@ func unmarshalValidateCallCall(origin, returnCode []byte, txid *[]byte) func(str
|
|||||||
if bytes.Compare(response.Data.TxId, *txid) != 0 {
|
if bytes.Compare(response.Data.TxId, *txid) != 0 {
|
||||||
return fmt.Errorf("TxIds do not match up! Got %x, expected %x", response.Data.TxId, *txid)
|
return fmt.Errorf("TxIds do not match up! Got %x, expected %x", response.Data.TxId, *txid)
|
||||||
}
|
}
|
||||||
// calldata := response.Data.CallData
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,6 +406,11 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
|
|||||||
if outAcc == nil || len(outAcc.Code) == 0 {
|
if outAcc == nil || len(outAcc.Code) == 0 {
|
||||||
// if you call an account that doesn't exist
|
// if you call an account that doesn't exist
|
||||||
// or an account with no code then we take fees (sorry pal)
|
// or an account with no code then we take fees (sorry pal)
|
||||||
|
// NOTE: it's fine to create a contract and call it within one
|
||||||
|
// block (nonce will prevent re-ordering of those txs)
|
||||||
|
// but to create with one account and call with another
|
||||||
|
// you have to wait a block to avoid a re-ordering attack
|
||||||
|
// that will take your fees
|
||||||
inAcc.Balance -= tx.Fee
|
inAcc.Balance -= tx.Fee
|
||||||
blockCache.UpdateAccount(inAcc)
|
blockCache.UpdateAccount(inAcc)
|
||||||
if outAcc == nil {
|
if outAcc == nil {
|
||||||
@ -457,7 +462,7 @@ func ExecTx(blockCache *BlockCache, tx_ types.Tx, runCall bool, evc events.Firea
|
|||||||
// a separate event will be fired from vm for each additional call
|
// a separate event will be fired from vm for each additional call
|
||||||
if evc != nil {
|
if evc != nil {
|
||||||
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventMsgCallTx{tx, ret, exception})
|
evc.FireEvent(types.EventStringAccInput(tx.Input.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||||
evc.FireEvent(types.EventStringAccReceive(tx.Address), types.EventMsgCallTx{tx, ret, exception})
|
evc.FireEvent(types.EventStringAccOutput(tx.Address), types.EventMsgCallTx{tx, ret, exception})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// The mempool does not call txs until
|
// The mempool does not call txs until
|
||||||
|
5
vm/vm.go
5
vm/vm.go
@ -76,10 +76,7 @@ func (vm *VM) Call(caller, callee *Account, code, input []byte, value uint64, ga
|
|||||||
|
|
||||||
exception := new(string)
|
exception := new(string)
|
||||||
defer func() {
|
defer func() {
|
||||||
// if callDepth is 0 the event is fired from ExecTx (along with the Input event)
|
if vm.evc != nil {
|
||||||
// otherwise, we fire from here.
|
|
||||||
if vm.callDepth != 0 && vm.evc != nil {
|
|
||||||
fmt.Println("FIRE AWAY!", types.EventStringAccReceive(callee.Address.Postfix(20)))
|
|
||||||
vm.evc.FireEvent(types.EventStringAccReceive(callee.Address.Postfix(20)), types.EventMsgCall{
|
vm.evc.FireEvent(types.EventStringAccReceive(callee.Address.Postfix(20)), types.EventMsgCall{
|
||||||
&types.CallData{caller.Address.Postfix(20), callee.Address.Postfix(20), input, value, *gas},
|
&types.CallData{caller.Address.Postfix(20), callee.Address.Postfix(20), input, value, *gas},
|
||||||
vm.origin.Postfix(20),
|
vm.origin.Postfix(20),
|
||||||
|
Reference in New Issue
Block a user