Issues during implementation of custom ETH settler
Asked Answered
C

1

6

I have investigated and played with corda-settler project. Following the recommendations within the documentation, I have created a custom ethereum module (with an outline similar to the ripple module), providing the option to settle obligations using off-ledger payments in ETH. The implementation (https://github.com/vladichhh/corda-settler) consists of the following significant pieces:

flows
    MakeEthPayment
services
    ETHClient
    ETHService
types
    EthPayment
    EthSettlement
token
    registered DigitalCurrency for ETH
oracle
    added logic for ETH payment verification

MakeEthPayment.kt

@Suspendable
override fun makePayment(obligation: Obligation<*>, amount: Amount<T>): EthPayment<T> {

    // get ETHService client
    val ethClient = serviceHub.cordaService(ETHService::class.java).client

    val recipient = obligation.settlementMethod?.accountToPay.toString()
    val amountToSend = amount.quantity.toString()

    // trigger ETH transfer
    val txHash = ethClient.sendEth(recipient, amountToSend)

    // return the payment
    return EthPayment(txHash, amount, PaymentStatus.SENT)
}

ETHClient.kt

fun sendEth(recipient: String, amount: String): String {
    val weiAmount: BigInteger = Convert.toWei(amount, Convert.Unit.GWEI).toBigInteger()

    val credentials: Credentials = WalletUtils.loadCredentials(walletPassword, walletFile)

    val transactionReceipt: TransactionReceipt = Transfer
            .sendFunds(web3j, credentials, recipient, BigDecimal(weiAmount), Convert.Unit.WEI)
            .send()

    return transactionReceipt.transactionHash
}

In order to send the required ETH amount to the specified recipient account, we have to do some Ethereum specific stuff:

  • we are connecting to Ethereum public blockchain environment, using “web3j” library
  • in order to trigger am Etherem transaction and transfer specified ETH amount, "web3j" requires an access to the file, containing encrypted sender's wallet
  • thus we have to provide password (to decrypt wallet) and location of the file, containing encrypted sender's wallet

And here are the issues:

  • I got the exception that the file could not be found, no matter where I am putting it. I have checked even the “swift” implementation and tried to use the class loader to load my file, but without success.
  • I suppose, the file with encrypted sender’s wallet should be located on one of the following places:
corda-settler/ethereum/src/main/resources/file.tmp
corda-settler/cordapp/src/main/resources/file.tmp
  • Finally I have hardcoded the location in that way:
/Users/vladimirhristov/WebstormProjects/Corda/corda-settler/cordapp/src/main/resources/file.tmp

and seems that the file was found but got another exception:

java.lang.OutOfMemoryError - screenshot

Seems that the operation of wallet decryption is highly consuming, which breaks maybe the flow. There is an option to reduce the algorithm complexity of the wallet generation, which will reflect in lower resources required to decrypt the same wallet at the next step, but this will reduce the security as well.

And here are my three basic questions ...

  1. How could I specify (location/mechanism) and make flow to find successfully my file, containing the sender’s encrypted wallet ?
  2. How could I access a files in the flow, or if there is another mechanism to attach only the file with encrypted wallet and pass the decryption to core Corda ?
  3. Do I need just to increase node resources (tuning JVM params increasing -Xms/-Xmx) in order to avoid OutOfMemoryError ?

Content of the file (containing encrypted sender’s wallet):

file.tmp

{"version":3,"id":"ecb51768-8564-498a-bb11-3a5a5c8dc0bb","address":"2bafc482bd227dfd5ba250521a00be3a4cc88bbd","crypto":{"ciphertext":"e0511415792dfa7221ba1b8f32b8ec98e1410f45e612e2100df1aceddfdb22bd","cipherparams":{"iv":"7ffa2af08f502c63d57e62440ad77539"},"cipher":"aes-128-ctr","kdf":"scrypt","kdfparams":{"dklen":32,"salt":"8051a5df1c02eb3eba81d2920fbb84b76b948a1248bbba62ffff684e733948cf","n":131072,"r":8,"p":1},"mac":"be23fe0e261ba38892581d80afd0c86563748377b5cc702b6ed3285a13cceff6"}}

I will appreciate any help! Thanks in advance :)

Chevy answered 9/7, 2019 at 22:30 Comment(1)
Hey @Chevy - thanks for your questions. I have a couple of follow-ups. Is this repo available as a PR against the tokens SDK? Is there anyway I could pull down / review? Also how are you deploying your nodes? The root directory of the deployed Corda node is different than the root of the repository (e.g. src/main may not be easily accessible). You may have to create a seperate gradle task to copy the files into the deployed nodes directory (if you are hoping to test locally)Brigette
A
0

VERY strange that Corda is giving you an out of memory error when running that flow.

I'd actually say that we'd need to be able to see the code for the flow in order to know how it could have run out of memory.

Are you running it in a container? Just make sure that you're meeting the requirements to run a JVM with an application on top.

tl;dr use a 8GB RAM machine to run your Corda node on the latest version of corda that should hopefully solve this issue.

Here's the docs page on the memory requirements; https://docs.corda.net/docs/corda-enterprise/4.5/node/performance-results.html#sizing

Abwatt answered 29/6, 2020 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.