Skip to content

Commit 1370e70

Browse files
author
Ed Gamble
authored
Merge pull request #274 from breadwallet/bugfix/CORE-606
CORE-606: Address TSAN #3; Improve EWM locking
2 parents 2738125 + 6d8995d commit 1370e70

12 files changed

Lines changed: 202 additions & 564 deletions

Swift/BRCore.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,16 +1346,16 @@
13461346
3C97E24422416AB1003FD88F /* BRCryptoAmount.c */,
13471347
3C97E254224170B9003FD88F /* BRCryptoAccount.h */,
13481348
3C97E255224170B9003FD88F /* BRCryptoAccount.c */,
1349-
CE179CA6233A4FF400633B97 /* BRCryptoCipher.c */,
13501349
CE179CA5233A4FF400633B97 /* BRCryptoCipher.h */,
1351-
CE5E43C223390FBB001E9238 /* BRCryptoCoder.c */,
1350+
CE179CA6233A4FF400633B97 /* BRCryptoCipher.c */,
13521351
CE5E43C323390FBB001E9238 /* BRCryptoCoder.h */,
1353-
CE5E43BE233902A4001E9238 /* BRCryptoHasher.c */,
1352+
CE5E43C223390FBB001E9238 /* BRCryptoCoder.c */,
13541353
CE5E43BF233902A4001E9238 /* BRCryptoHasher.h */,
1354+
CE5E43BE233902A4001E9238 /* BRCryptoHasher.c */,
13551355
3C1D1F2322F0F1740028B20C /* BRCryptoKey.h */,
13561356
3C1D1F2422F0F1740028B20C /* BRCryptoKey.c */,
1357-
CE5E43C6233930F1001E9238 /* BRCryptoSigner.c */,
13581357
CE5E43C7233930F1001E9238 /* BRCryptoSigner.h */,
1358+
CE5E43C6233930F1001E9238 /* BRCryptoSigner.c */,
13591359
3C97E258224170EC003FD88F /* BRCryptoAddress.h */,
13601360
3C97E259224170EC003FD88F /* BRCryptoAddress.c */,
13611361
3CCC61E9228C7FB500C0A13E /* BRCryptoFeeBasis.h */,

crypto/BRCryptoFeeBasis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <math.h>
1212

1313
#include "BRCryptoFeeBasis.h"
14-
#include "ethereum/ewm/BREthereumBase.h"
14+
#include "ethereum/BREthereum.h"
1515
#include "generic/BRGeneric.h"
1616
#include "BRCryptoPrivate.h"
1717

crypto/BRCryptoTransfer.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
#include "support/BRAddress.h"
1818
#include "bitcoin/BRWallet.h"
1919
#include "bitcoin/BRTransaction.h"
20-
#include "ethereum/util/BRUtil.h"
2120
#include "ethereum/BREthereum.h"
22-
#include "ethereum/ewm/BREthereumTransfer.h"
2321

2422
/**
2523
*
@@ -46,6 +44,7 @@ struct BRCryptoTransferRecord {
4644
uint64_t recv;
4745
} btc;
4846
struct {
47+
BREthereumEWM ewm;
4948
BREthereumTransfer tid;
5049
BREthereumAddress accountAddress;
5150
} eth;
@@ -199,10 +198,11 @@ cryptoTransferCreateAsETH (BRCryptoUnit unit,
199198
BREthereumTransfer tid,
200199
BRCryptoFeeBasis feeBasisEstimated) {
201200
BRCryptoTransfer transfer = cryptoTransferCreateInternal (BLOCK_CHAIN_TYPE_ETH, unit, unitForFee);
201+
transfer->u.eth.ewm = ewm;
202202
transfer->u.eth.tid = tid;
203203

204-
transfer->sourceAddress = cryptoAddressCreateAsETH (transferGetSourceAddress (tid));
205-
transfer->targetAddress = cryptoAddressCreateAsETH (transferGetTargetAddress (tid));
204+
transfer->sourceAddress = cryptoAddressCreateAsETH (ewmTransferGetSource (ewm, tid));
205+
transfer->targetAddress = cryptoAddressCreateAsETH (ewmTransferGetTarget (ewm, tid));
206206

207207
// cache the values that require the ewm
208208
BREthereumAccount account = ewmGetAccount (ewm);
@@ -234,7 +234,7 @@ cryptoTransferCreateAsETH (BRCryptoUnit unit,
234234
// Thus: if `feeBasisEstimated` is NULL, we'll take the ETH fee basis (as the best we have).
235235

236236
// Get the ETH feeBasis, in the event that we need it.
237-
BREthereumFeeBasis ethFeeBasis = transferGetFeeBasis(tid);
237+
BREthereumFeeBasis ethFeeBasis = ewmTransferGetFeeBasis (ewm, tid);
238238

239239
transfer->feeBasisEstimated = (NULL == feeBasisEstimated
240240
? cryptoFeeBasisCreateAsETH (unitForFee,
@@ -328,7 +328,8 @@ cryptoTransferGetAmountAsSign (BRCryptoTransfer transfer, BRCryptoBoolean isNega
328328
}
329329

330330
case BLOCK_CHAIN_TYPE_ETH: {
331-
BREthereumAmount ethAmount = transferGetAmount(transfer->u.eth.tid);
331+
BREthereumAmount ethAmount = ewmTransferGetAmount (transfer->u.eth.ewm,
332+
transfer->u.eth.tid);
332333
switch (amountGetType(ethAmount)) {
333334
case AMOUNT_ETHER:
334335
amount = cryptoAmountCreate (transfer->unit,
@@ -509,10 +510,11 @@ cryptoTransferGetDirection (BRCryptoTransfer transfer) {
509510
return CRYPTO_TRANSFER_RECEIVED;
510511
}
511512
case BLOCK_CHAIN_TYPE_ETH: {
512-
BREthereumTransfer tid =transfer->u.eth.tid;
513+
BREthereumEWM ewm = transfer->u.eth.ewm;
514+
BREthereumTransfer tid = transfer->u.eth.tid;
513515

514-
BREthereumAddress source = transferGetSourceAddress (tid);
515-
BREthereumAddress target = transferGetTargetAddress (tid);
516+
BREthereumAddress source = ewmTransferGetSource (ewm, tid);
517+
BREthereumAddress target = ewmTransferGetTarget (ewm, tid);
516518

517519
BREthereumBoolean accountIsSource = addressEqual (source, transfer->u.eth.accountAddress);
518520
BREthereumBoolean accountIsTarget = addressEqual (target, transfer->u.eth.accountAddress);
@@ -563,9 +565,10 @@ cryptoTransferGetHash (BRCryptoTransfer transfer) {
563565
: cryptoHashCreateAsBTC (hash));
564566
}
565567
case BLOCK_CHAIN_TYPE_ETH: {
566-
BREthereumTransfer tid =transfer->u.eth.tid;
568+
BREthereumEWM ewm = transfer->u.eth.ewm;
569+
BREthereumTransfer tid = transfer->u.eth.tid;
567570

568-
BREthereumHash hash = transferGetOriginatingTransactionHash (tid);
571+
BREthereumHash hash = ewmTransferGetOriginatingTransactionHash (ewm, tid);
569572
return (ETHEREUM_BOOLEAN_TRUE == hashEqual(hash, hashCreateEmpty())
570573
? NULL
571574
: cryptoHashCreateAsETH (hash));

crypto/BRCryptoWallet.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
#include "BRCryptoBase.h"
1616
#include "BRCryptoPrivate.h"
1717

18-
#include "generic/BRGeneric.h"
1918

2019
#include "bitcoin/BRWallet.h"
2120
#include "bitcoin/BRWalletManager.h"
2221
#include "ethereum/BREthereum.h"
23-
#include "ethereum/ewm/BREthereumTransfer.h"
22+
#include "generic/BRGeneric.h"
2423

2524
/**
2625
*

crypto/BRCryptoWalletManagerClient.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#include "bitcoin/BRWalletManager.h"
2222
#include "ethereum/BREthereum.h"
23-
#include "ethereum/ewm/BREthereumTransfer.h"
2423
#include "support/BRBase.h"
2524
#include "support/BRSyncMode.h"
2625

@@ -1280,7 +1279,7 @@ cwmTransactionEventAsETH (BREthereumClientContext context,
12801279

12811280
BRCryptoTransferState oldState = cryptoTransferGetState (transfer);
12821281

1283-
BREthereumFeeBasis ethFeeBasis = transferGetFeeBasis (tid);
1282+
BREthereumFeeBasis ethFeeBasis = ewmTransferGetFeeBasis (ewm, tid);
12841283

12851284
BRCryptoUnit unit = cryptoTransferGetUnitForFee(transfer);
12861285
BRCryptoFeeBasis feeBasisConfirmed = cryptoFeeBasisCreateAsETH (unit,

ethereum/base/BREthereumFeeBasis.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ feeBasisCreate (BREthereumGas limit,
1919
};
2020
}
2121

22+
extern BREthereumGas
23+
feeBasisGetGasLimit (BREthereumFeeBasis basis) {
24+
return (FEE_BASIS_GAS == basis.type ? basis.u.gas.limit : gasCreate(0));
25+
}
26+
27+
extern BREthereumGasPrice
28+
feeBasisGetGasPrice (BREthereumFeeBasis basis) {
29+
return (FEE_BASIS_GAS == basis.type ? basis.u.gas.price : gasPriceCreate(etherCreateZero()));
30+
}
31+
2232
extern BREthereumEther
2333
feeBasisGetFee (BREthereumFeeBasis feeBasis, int *overflow) { // BREthereumBoolean
2434
*overflow = 0;

ethereum/base/BREthereumFeeBasis.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ extern BREthereumFeeBasis
3232
feeBasisCreate (BREthereumGas limit,
3333
BREthereumGasPrice price);
3434

35+
extern BREthereumGas
36+
feeBasisGetGasLimit (BREthereumFeeBasis basis);
37+
38+
extern BREthereumGasPrice
39+
feeBasisGetGasPrice (BREthereumFeeBasis basis);
40+
3541
extern BREthereumEther
3642
feeBasisGetFee (BREthereumFeeBasis feeBasis, int *overflow);
3743

0 commit comments

Comments
 (0)