Skip to content

Commit

Permalink
(Minor) Minimize conflicts with feature branches (#1765)
Browse files Browse the repository at this point in the history
* optional label in getReceiveAddress

* use a separate variable for channel version
  • Loading branch information
pm47 committed Apr 13, 2021
1 parent 205653d commit ccae92d
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion eclair-core/src/main/scala/fr/acinq/eclair/Eclair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class EclairImpl(appKit: Kit) extends Eclair {

override def newAddress(): Future[String] = {
appKit.wallet match {
case w: BitcoinCoreWallet => w.getReceiveAddress
case w: BitcoinCoreWallet => w.getReceiveAddress()
case _ => Future.failed(new IllegalArgumentException("this call is only available with a bitcoin core backend"))
}
}
Expand Down
2 changes: 1 addition & 1 deletion eclair-core/src/main/scala/fr/acinq/eclair/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class Setup(datadir: File,
_ <- Future.firstCompletedOf(routerInitialized.future :: routerTimeout :: Nil)

wallet = new BitcoinCoreWallet(bitcoin)
_ = wallet.getReceiveAddress.map(address => logger.info(s"initial wallet address=$address"))
_ = wallet.getReceiveAddress().map(address => logger.info(s"initial wallet address=$address"))

// do not change the name of this actor. it is used in the configuration to specify a custom bounded mailbox
backupHandler = if (config.getBoolean("enable-db-backup")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ trait EclairWallet {

def getBalance: Future[OnChainBalance]

def getReceiveAddress: Future[String]
/**
* @param label used if implemented with bitcoin core, can be ignored by implementation
*/
def getReceiveAddress(label: String = ""): Future[String]

def getReceivePubkey(receiveAddress: Option[String] = None): Future[PublicKey]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class BitcoinCoreWallet(rpcClient: BitcoinJsonRPCClient)(implicit ec: ExecutionC
OnChainBalance(toSatoshi(confirmed), toSatoshi(unconfirmed))
})

override def getReceiveAddress: Future[String] = for {
JString(address) <- rpcClient.invoke("getnewaddress")
override def getReceiveAddress(label: String): Future[String] = for {
JString(address) <- rpcClient.invoke("getnewaddress", label)
} yield address

override def getReceivePubkey(receiveAddress: Option[String] = None): Future[Crypto.PublicKey] = for {
address <- receiveAddress.map(Future.successful).getOrElse(getReceiveAddress)
address <- receiveAddress.map(Future.successful).getOrElse(getReceiveAddress())
JString(rawKey) <- rpcClient.invoke("getaddressinfo", address).map(_ \ "pubkey")
} yield PublicKey(ByteVector.fromValidHex(rawKey))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ object Helpers {
/** NB: this is a blocking call, use carefully! */
def getFinalScriptPubKey(wallet: EclairWallet, chainHash: ByteVector32): ByteVector = {
import scala.concurrent.duration._
val finalAddress = Await.result(wallet.getReceiveAddress, 40 seconds)
val finalAddress = Await.result(wallet.getReceiveAddress(), 40 seconds)

Script.write(addressToPublicKeyScript(finalAddress, chainHash))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TestWallet extends EclairWallet {

override def getBalance: Future[OnChainBalance] = Future.successful(OnChainBalance(1105 sat, 561 sat))

override def getReceiveAddress: Future[String] = Future.successful("bcrt1qwcv8naajwn8fjhu8z59q9e6ucrqr068rlcenux")
override def getReceiveAddress(label: String): Future[String] = Future.successful("bcrt1qwcv8naajwn8fjhu8z59q9e6ucrqr068rlcenux")

override def getReceivePubkey(receiveAddress: Option[String] = None): Future[Crypto.PublicKey] = Future.successful(PublicKey(hex"028feba10d0eafd0fad8fe20e6d9206e6bd30242826de05c63f459a00aced24b12"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class BitcoinCoreWalletSpec extends TestKitBaseClass with BitcoindService with A
wallet.getBalance.pipeTo(sender.ref)
assert(sender.expectMsgType[OnChainBalance].confirmed > 0.sat)

wallet.getReceiveAddress.pipeTo(sender.ref)
wallet.getReceiveAddress().pipeTo(sender.ref)
val address = sender.expectMsgType[String]
assert(Try(addressToPublicKeyScript(address, Block.RegtestGenesisBlock.hash)).isSuccess)

Expand Down Expand Up @@ -231,7 +231,7 @@ class BitcoinCoreWalletSpec extends TestKitBaseClass with BitcoindService with A
wallet.getBalance.pipeTo(sender.ref)
assert(sender.expectMsgType[OnChainBalance].confirmed > 0.sat)

wallet.getReceiveAddress.pipeTo(sender.ref)
wallet.getReceiveAddress().pipeTo(sender.ref)
val address = sender.expectMsgType[String]
assert(Try(addressToPublicKeyScript(address, Block.RegtestGenesisBlock.hash)).isSuccess)

Expand Down Expand Up @@ -274,7 +274,7 @@ class BitcoinCoreWalletSpec extends TestKitBaseClass with BitcoindService with A
val sender = TestProbe()
val wallet = new BitcoinCoreWallet(bitcoinrpcclient)

wallet.getReceiveAddress.pipeTo(sender.ref)
wallet.getReceiveAddress().pipeTo(sender.ref)
val address = sender.expectMsgType[String]

wallet.getReceivePubkey(receiveAddress = Some(address)).pipeTo(sender.ref)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class TxPublisherSpec extends TestKitBaseClass with AnyFunSuiteLike with Bitcoin
val bitcoinWallet = new BitcoinCoreWallet(walletRpcClient)
val probe = TestProbe()
utxos.foreach(amount => {
bitcoinWallet.getReceiveAddress.pipeTo(probe.ref)
bitcoinWallet.getReceiveAddress().pipeTo(probe.ref)
val walletAddress = probe.expectMsgType[String]
sendToAddress(walletAddress, amount, probe)
})
Expand Down Expand Up @@ -279,7 +279,7 @@ class TxPublisherSpec extends TestKitBaseClass with AnyFunSuiteLike with Bitcoin
assert(mempoolTx1.txid === commitTx.txid)

// add more funds to our wallet
bitcoinWallet.getReceiveAddress.pipeTo(probe.ref)
bitcoinWallet.getReceiveAddress().pipeTo(probe.ref)
val walletAddress = probe.expectMsgType[String]
sendToAddress(walletAddress, 1 millibtc, probe)
createBlocks(1)
Expand Down Expand Up @@ -456,7 +456,7 @@ class TxPublisherSpec extends TestKitBaseClass with AnyFunSuiteLike with Bitcoin
txPublisher ! ParentTxConfirmed(htlcSuccess, commitTx.txid)

// Add more funds to our wallet to allow bumping HTLC txs.
bitcoinWallet.getReceiveAddress.pipeTo(probe.ref)
bitcoinWallet.getReceiveAddress().pipeTo(probe.ref)
val walletAddress = probe.expectMsgType[String]
sendToAddress(walletAddress, 1 millibtc, probe)
createBlocks(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ class WaitForFundingCreatedInternalStateSpec extends TestKitBaseClass with Fixtu
}
val setup = init(wallet = noopWallet)
import setup._
val channelVersion = ChannelVersion.STANDARD
val aliceInit = Init(Alice.channelParams.features)
val bobInit = Init(Bob.channelParams.features)
within(30 seconds) {
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, channelVersion)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, channelVersion)
alice2bob.expectMsgType[OpenChannel]
alice2bob.forward(bob)
bob2alice.expectMsgType[AcceptChannel]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ class WaitForFundingCreatedStateSpec extends TestKitBaseClass with FixtureAnyFun
val setup = init(aliceNodeParams, bobNodeParams)

import setup._
val channelVersion = ChannelVersion.STANDARD
val aliceInit = Init(aliceParams.features)
val bobInit = Init(bobParams.features)
within(30 seconds) {
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, fundingSatoshis, pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, aliceParams, alice2bob.ref, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, fundingSatoshis, pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, aliceParams, alice2bob.ref, bobInit, ChannelFlags.Empty, channelVersion)
alice2blockchain.expectMsgType[TxPublisher.SetChannelId]
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, bobParams, bob2alice.ref, aliceInit, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, bobParams, bob2alice.ref, aliceInit, channelVersion)
bob2blockchain.expectMsgType[TxPublisher.SetChannelId]
alice2bob.expectMsgType[OpenChannel]
alice2bob.forward(bob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ class WaitForFundingSignedStateSpec extends TestKitBaseClass with FixtureAnyFunS
val setup = init(aliceNodeParams, bobNodeParams)

import setup._
val channelVersion = ChannelVersion.STANDARD
val aliceInit = Init(aliceParams.features)
val bobInit = Init(bobParams.features)
within(30 seconds) {
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, fundingSatoshis, pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, aliceParams, alice2bob.ref, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, fundingSatoshis, pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, aliceParams, alice2bob.ref, bobInit, ChannelFlags.Empty, channelVersion)
alice2blockchain.expectMsgType[TxPublisher.SetChannelId]
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, bobParams, bob2alice.ref, aliceInit, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, bobParams, bob2alice.ref, aliceInit, channelVersion)
bob2blockchain.expectMsgType[TxPublisher.SetChannelId]
alice2bob.expectMsgType[OpenChannel]
alice2bob.forward(bob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ class WaitForFundingConfirmedStateSpec extends TestKitBaseClass with FixtureAnyF
override def withFixture(test: OneArgTest): Outcome = {
val setup = init()
import setup._
val channelVersion = ChannelVersion.STANDARD
val aliceInit = Init(Alice.channelParams.features)
val bobInit = Init(Bob.channelParams.features)
within(30 seconds) {
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, channelVersion)
alice2blockchain.expectMsgType[TxPublisher.SetChannelId]
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, channelVersion)
bob2blockchain.expectMsgType[TxPublisher.SetChannelId]
alice2bob.expectMsgType[OpenChannel]
alice2bob.forward(bob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ class WaitForFundingLockedStateSpec extends TestKitBaseClass with FixtureAnyFunS
override def withFixture(test: OneArgTest): Outcome = {
val setup = init()
import setup._
val channelVersion = ChannelVersion.STANDARD
val aliceInit = Init(Alice.channelParams.features)
val bobInit = Init(Bob.channelParams.features)
within(30 seconds) {
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, Some(initialRelayFees), Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, Some(initialRelayFees), Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, channelVersion)
alice2blockchain.expectMsgType[TxPublisher.SetChannelId]
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, channelVersion)
bob2blockchain.expectMsgType[TxPublisher.SetChannelId]
alice2bob.expectMsgType[OpenChannel]
alice2bob.forward(bob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ class ClosingStateSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike with

if (unconfirmedFundingTx) {
within(30 seconds) {
val channelVersion = ChannelVersion.STANDARD
val aliceInit = Init(Alice.channelParams.features)
val bobInit = Init(Bob.channelParams.features)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, TestConstants.fundingSatoshis, TestConstants.pushMsat, TestConstants.feeratePerKw, TestConstants.feeratePerKw, None, Alice.channelParams, alice2bob.ref, bobInit, ChannelFlags.Empty, channelVersion)
alice2blockchain.expectMsgType[TxPublisher.SetChannelId]
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, bob2alice.ref, aliceInit, channelVersion)
bob2blockchain.expectMsgType[TxPublisher.SetChannelId]
alice2bob.expectMsgType[OpenChannel]
alice2bob.forward(bob)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,16 @@ class RustyTestsSpec extends TestKitBaseClass with Matchers with FixtureAnyFunSu
val feeEstimator = new TestFeeEstimator
val aliceNodeParams = Alice.nodeParams.copy(blockCount = blockCount, onChainFeeConf = Alice.nodeParams.onChainFeeConf.copy(feeEstimator = feeEstimator))
val bobNodeParams = Bob.nodeParams.copy(blockCount = blockCount, onChainFeeConf = Bob.nodeParams.onChainFeeConf.copy(feeEstimator = feeEstimator))
val channelVersion = ChannelVersion.STANDARD
val alice: TestFSMRef[State, Data, Channel] = TestFSMRef(new Channel(aliceNodeParams, wallet, Bob.nodeParams.nodeId, alice2blockchain.ref, relayer, FakeTxPublisherFactory(alice2blockchain)), alicePeer.ref)
val bob: TestFSMRef[State, Data, Channel] = TestFSMRef(new Channel(bobNodeParams, wallet, Alice.nodeParams.nodeId, bob2blockchain.ref, relayer, FakeTxPublisherFactory(bob2blockchain)), bobPeer.ref)
val aliceInit = Init(Alice.channelParams.features)
val bobInit = Init(Bob.channelParams.features)
// alice and bob will both have 1 000 000 sat
feeEstimator.setFeerate(FeeratesPerKw.single(FeeratePerKw(10000 sat)))
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, 2000000 sat, 1000000000 msat, feeEstimator.getFeeratePerKw(target = 2), feeEstimator.getFeeratePerKw(target = 6), None, Alice.channelParams, pipe, bobInit, ChannelFlags.Empty, ChannelVersion.STANDARD)
alice ! INPUT_INIT_FUNDER(ByteVector32.Zeroes, 2000000 sat, 1000000000 msat, feeEstimator.getFeeratePerKw(target = 2), feeEstimator.getFeeratePerKw(target = 6), None, Alice.channelParams, pipe, bobInit, ChannelFlags.Empty, channelVersion)
alice2blockchain.expectMsgType[TxPublisher.SetChannelId]
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, pipe, aliceInit, ChannelVersion.STANDARD)
bob ! INPUT_INIT_FUNDEE(ByteVector32.Zeroes, Bob.channelParams, pipe, aliceInit, channelVersion)
bob2blockchain.expectMsgType[TxPublisher.SetChannelId]
pipe ! (alice, bob)
within(30 seconds) {
Expand Down

0 comments on commit ccae92d

Please sign in to comment.