【问题标题】:How can a Corda flow be written to minimise the size of checkpoints如何编写 Corda 流以最小化检查点的大小
【发布时间】:2018-07-19 20:51:10
【问题描述】:

Corda 在various operations 之前流动检查点。如何编写流程以最小化检查点大小并缩短流程运行时间?

【问题讨论】:

    标签: corda


    【解决方案1】:

    您可以通过保持调用堆栈最小化来减少检查点的大小,因为执行堆栈范围内的任何内容都将被序列化到检查点中。

    减少调用堆栈的一种方法是将任何未挂起的操作分解为未标记为@Suspendable 的辅助函数。

    例如,假设我们写:

    @Suspendable
    fun asd() {
      val something = computeSomething()
      val somethingElse = lol(something)
      sendAndReceive(bla)
    }
    

    在这种情况下,somethingsomethingElse 将在检查点中。所以我们应该写:

    @Suspendable
    fun asd() {
      helper()
      sendAndReceive(bla)
    }
    
    fun helper() {
      val something = computeSomething()
      val somethingElse = lol(something)
    }
    

    并且somethingsomethingElse 不会在检查点中。

    【讨论】:

    • 没有。 helper 中使用的局部变量没有检查点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    相关资源
    最近更新 更多