批处理中的事务是否序列化?
Are transactions in a batch serialized?
如果我发送一个带有 2 个合约 fn 调用的交易,如果第一个失败,第二个是否会被执行?
示例代码:
const actions = [
TX.functionCall("select_staking_pool", { staking_pool_account_id: stakingPool }, this.BASE_GAS.muln(3), new BN(0)),
TX.functionCall("deposit_and_stake", { amount: near.ntoy(amountNear) }, this.BASE_GAS.muln(5), new BN(0))
]
return near.broadcast_tx_commit_actions(actions, sender, lockupContract, privateKey)
我确实执行了这批,但结果没有给我明确的答案:https://explorer.testnet.near.org/transactions/DcchgGdzAVEvNqRReHkjsmrTr5PoaMoibs3fyKoKBYSe
回执日志中的第一个 fn 调用 code uses cross-contract calls and a callback code to check if the contract is whitelisted, but I can't see the callback's log code。我认为第一次调用失败是因为第二次调用失败并出现错误:“未选择质押池”
完整结果如下:
{
"status": {
"Failure": {
"ActionError": {
"index": 1,
"kind": {
"FunctionCallError": {
"HostError": {
"GuestPanic": {
"panic_msg": "panicked at 'Staking pool is not selected', src/internal.rs:90:9"
}
}
}
}
}
}
},
"transaction": {
"signer_id": "lucio.testnet",
"public_key": "ed25519:Cvqie7SJ6xmLNA5KoTAYoUAkhD25KaJLG6N9oSmzT9FK",
"nonce": 33,
"receiver_id": "274e981786efcabbe87794f20348c1b2af6e7963.lockupy.testnet",
"actions": [
{
"FunctionCall": {
"method_name": "select_staking_pool",
"args": "eyJzdGFraW5nX3Bvb2xfYWNjb3VudF9pZCI6Im5vcnRoZXJubGlnaHRzLnN0YWtpbmdwb29sIn0=",
"gas": 75000000000000,
"deposit": "0"
}
},
{
"FunctionCall": {
"method_name": "deposit_and_stake",
"args": "eyJhbW91bnQiOiIxMDk0OTkwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIn0=",
"gas": 125000000000000,
"deposit": "0"
}
}
],
"signature": "ed25519:gzCsrcobVtjuD6FE4qDhgo9zdk2feBp6dfa66NZYLPTnwypF7g8mDM7yubcnkVcF1sPzEFeEfJtQ4hwwnhrxTa6",
"hash": "EjiQBjzF6Ea74wSHkjmZMkhTGwgYxbUdeVKUvzaA8X7k"
},
"transaction_outcome": {
"proof": [],
"block_hash": "3xEuw43E1W4FP2q1Un6XLsDSbhRc7c7FMtGWWL6i3KJj",
"id": "EjiQBjzF6Ea74wSHkjmZMkhTGwgYxbUdeVKUvzaA8X7k",
"outcome": {
"logs": [],
"receipt_ids": [
"75pJCVuheYCjX82RspQzoKm5v7NSG1QNUaPK7DRzZYNt"
],
"gas_burnt": 4748079879222,
"tokens_burnt": "474807987922200000000",
"executor_id": "lucio.testnet",
"status": {
"SuccessReceiptId": "75pJCVuheYCjX82RspQzoKm5v7NSG1QNUaPK7DRzZYNt"
}
}
},
"receipts_outcome": [
{
"proof": [
{
"hash": "55YXLhqDc63f8n4MdZNwi6TdmtFkaYp18wKwm7qFmDo5",
"direction": "Left"
}
],
"block_hash": "DB3p49tiSBfRLv5diDUStajtDiMNs2KroKfRcr2cQDnV",
"id": "75pJCVuheYCjX82RspQzoKm5v7NSG1QNUaPK7DRzZYNt",
"outcome": {
"logs": [
"Selecting staking pool @northernlights.stakingpool. Going to check whitelist first."
],
"receipt_ids": [
"HXStMQuf5aWKVpWDM1Hf4EdA3S4FLTGjmYaF2WAYRcUz"
],
"gas_burnt": 20291176638173,
"tokens_burnt": "2029117663817300000000",
"executor_id": "274e981786efcabbe87794f20348c1b2af6e7963.lockupy.testnet",
"status": {
"Failure": {
"ActionError": {
"index": 1,
"kind": {
"FunctionCallError": {
"HostError": {
"GuestPanic": {
"panic_msg": "panicked at 'Staking pool is not selected', src/internal.rs:90:9"
}
}
}
}
}
}
}
}
},
{
"proof": [],
"block_hash": "2kua8s7vjix2MiMHZ7Rzbrhyv8UbGFEpvWeT67H2qCYM",
"id": "HXStMQuf5aWKVpWDM1Hf4EdA3S4FLTGjmYaF2WAYRcUz",
"outcome": {
"logs": [],
"receipt_ids": [],
"gas_burnt": 0,
"tokens_burnt": "0",
"executor_id": "lucio.testnet",
"status": {
"SuccessValue": ""
}
}
}
]
}
编辑:PS。看起来第一个函数调用无声地失败了(关于 Tx 结果)。我测试了与 2 个独立事务相同的调用,第一个 (select_staking_pool) 成功。
不执行第一个失败操作之后的所有后续操作。他们的执行费用将退还。之前成功执行的所有更改都将被还原,所有承诺也不会被安排和执行。
你的情况更复杂,因为第一个动作通过返回一个承诺而成功。稍后生成的 promise 将在回调中失败,但第二个操作立即失败,因为由于异步执行尚未选择质押池。所以第一个承诺没有得到安排。
编辑 1.
一旦交易或收据成功(完成所有操作),它不会回滚任何内容。因此,如果任何未来的承诺失败,它们将相互独立执行。也只有一批操作中的最后一个操作 returns 整个收据的结果。
如果我发送一个带有 2 个合约 fn 调用的交易,如果第一个失败,第二个是否会被执行?
示例代码:
const actions = [
TX.functionCall("select_staking_pool", { staking_pool_account_id: stakingPool }, this.BASE_GAS.muln(3), new BN(0)),
TX.functionCall("deposit_and_stake", { amount: near.ntoy(amountNear) }, this.BASE_GAS.muln(5), new BN(0))
]
return near.broadcast_tx_commit_actions(actions, sender, lockupContract, privateKey)
我确实执行了这批,但结果没有给我明确的答案:https://explorer.testnet.near.org/transactions/DcchgGdzAVEvNqRReHkjsmrTr5PoaMoibs3fyKoKBYSe
回执日志中的第一个 fn 调用 code uses cross-contract calls and a callback code to check if the contract is whitelisted, but I can't see the callback's log code。我认为第一次调用失败是因为第二次调用失败并出现错误:“未选择质押池”
完整结果如下:
{
"status": {
"Failure": {
"ActionError": {
"index": 1,
"kind": {
"FunctionCallError": {
"HostError": {
"GuestPanic": {
"panic_msg": "panicked at 'Staking pool is not selected', src/internal.rs:90:9"
}
}
}
}
}
}
},
"transaction": {
"signer_id": "lucio.testnet",
"public_key": "ed25519:Cvqie7SJ6xmLNA5KoTAYoUAkhD25KaJLG6N9oSmzT9FK",
"nonce": 33,
"receiver_id": "274e981786efcabbe87794f20348c1b2af6e7963.lockupy.testnet",
"actions": [
{
"FunctionCall": {
"method_name": "select_staking_pool",
"args": "eyJzdGFraW5nX3Bvb2xfYWNjb3VudF9pZCI6Im5vcnRoZXJubGlnaHRzLnN0YWtpbmdwb29sIn0=",
"gas": 75000000000000,
"deposit": "0"
}
},
{
"FunctionCall": {
"method_name": "deposit_and_stake",
"args": "eyJhbW91bnQiOiIxMDk0OTkwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIn0=",
"gas": 125000000000000,
"deposit": "0"
}
}
],
"signature": "ed25519:gzCsrcobVtjuD6FE4qDhgo9zdk2feBp6dfa66NZYLPTnwypF7g8mDM7yubcnkVcF1sPzEFeEfJtQ4hwwnhrxTa6",
"hash": "EjiQBjzF6Ea74wSHkjmZMkhTGwgYxbUdeVKUvzaA8X7k"
},
"transaction_outcome": {
"proof": [],
"block_hash": "3xEuw43E1W4FP2q1Un6XLsDSbhRc7c7FMtGWWL6i3KJj",
"id": "EjiQBjzF6Ea74wSHkjmZMkhTGwgYxbUdeVKUvzaA8X7k",
"outcome": {
"logs": [],
"receipt_ids": [
"75pJCVuheYCjX82RspQzoKm5v7NSG1QNUaPK7DRzZYNt"
],
"gas_burnt": 4748079879222,
"tokens_burnt": "474807987922200000000",
"executor_id": "lucio.testnet",
"status": {
"SuccessReceiptId": "75pJCVuheYCjX82RspQzoKm5v7NSG1QNUaPK7DRzZYNt"
}
}
},
"receipts_outcome": [
{
"proof": [
{
"hash": "55YXLhqDc63f8n4MdZNwi6TdmtFkaYp18wKwm7qFmDo5",
"direction": "Left"
}
],
"block_hash": "DB3p49tiSBfRLv5diDUStajtDiMNs2KroKfRcr2cQDnV",
"id": "75pJCVuheYCjX82RspQzoKm5v7NSG1QNUaPK7DRzZYNt",
"outcome": {
"logs": [
"Selecting staking pool @northernlights.stakingpool. Going to check whitelist first."
],
"receipt_ids": [
"HXStMQuf5aWKVpWDM1Hf4EdA3S4FLTGjmYaF2WAYRcUz"
],
"gas_burnt": 20291176638173,
"tokens_burnt": "2029117663817300000000",
"executor_id": "274e981786efcabbe87794f20348c1b2af6e7963.lockupy.testnet",
"status": {
"Failure": {
"ActionError": {
"index": 1,
"kind": {
"FunctionCallError": {
"HostError": {
"GuestPanic": {
"panic_msg": "panicked at 'Staking pool is not selected', src/internal.rs:90:9"
}
}
}
}
}
}
}
}
},
{
"proof": [],
"block_hash": "2kua8s7vjix2MiMHZ7Rzbrhyv8UbGFEpvWeT67H2qCYM",
"id": "HXStMQuf5aWKVpWDM1Hf4EdA3S4FLTGjmYaF2WAYRcUz",
"outcome": {
"logs": [],
"receipt_ids": [],
"gas_burnt": 0,
"tokens_burnt": "0",
"executor_id": "lucio.testnet",
"status": {
"SuccessValue": ""
}
}
}
]
}
编辑:PS。看起来第一个函数调用无声地失败了(关于 Tx 结果)。我测试了与 2 个独立事务相同的调用,第一个 (select_staking_pool) 成功。
不执行第一个失败操作之后的所有后续操作。他们的执行费用将退还。之前成功执行的所有更改都将被还原,所有承诺也不会被安排和执行。
你的情况更复杂,因为第一个动作通过返回一个承诺而成功。稍后生成的 promise 将在回调中失败,但第二个操作立即失败,因为由于异步执行尚未选择质押池。所以第一个承诺没有得到安排。
编辑 1.
一旦交易或收据成功(完成所有操作),它不会回滚任何内容。因此,如果任何未来的承诺失败,它们将相互独立执行。也只有一批操作中的最后一个操作 returns 整个收据的结果。