Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-606: Address TSAN #3; Improve EWM locking #274

Merged
merged 11 commits into from
Oct 2, 2019
8 changes: 4 additions & 4 deletions Swift/BRCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1346,16 +1346,16 @@
3C97E24422416AB1003FD88F /* BRCryptoAmount.c */,
3C97E254224170B9003FD88F /* BRCryptoAccount.h */,
3C97E255224170B9003FD88F /* BRCryptoAccount.c */,
CE179CA6233A4FF400633B97 /* BRCryptoCipher.c */,
CE179CA5233A4FF400633B97 /* BRCryptoCipher.h */,
CE5E43C223390FBB001E9238 /* BRCryptoCoder.c */,
CE179CA6233A4FF400633B97 /* BRCryptoCipher.c */,
CE5E43C323390FBB001E9238 /* BRCryptoCoder.h */,
CE5E43BE233902A4001E9238 /* BRCryptoHasher.c */,
CE5E43C223390FBB001E9238 /* BRCryptoCoder.c */,
CE5E43BF233902A4001E9238 /* BRCryptoHasher.h */,
CE5E43BE233902A4001E9238 /* BRCryptoHasher.c */,
3C1D1F2322F0F1740028B20C /* BRCryptoKey.h */,
3C1D1F2422F0F1740028B20C /* BRCryptoKey.c */,
CE5E43C6233930F1001E9238 /* BRCryptoSigner.c */,
CE5E43C7233930F1001E9238 /* BRCryptoSigner.h */,
CE5E43C6233930F1001E9238 /* BRCryptoSigner.c */,
3C97E258224170EC003FD88F /* BRCryptoAddress.h */,
3C97E259224170EC003FD88F /* BRCryptoAddress.c */,
3CCC61E9228C7FB500C0A13E /* BRCryptoFeeBasis.h */,
Expand Down
2 changes: 1 addition & 1 deletion crypto/BRCryptoFeeBasis.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <math.h>

#include "BRCryptoFeeBasis.h"
#include "ethereum/ewm/BREthereumBase.h"
#include "ethereum/BREthereum.h"
#include "generic/BRGeneric.h"
#include "BRCryptoPrivate.h"

Expand Down
25 changes: 14 additions & 11 deletions crypto/BRCryptoTransfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include "support/BRAddress.h"
#include "bitcoin/BRWallet.h"
#include "bitcoin/BRTransaction.h"
#include "ethereum/util/BRUtil.h"
#include "ethereum/BREthereum.h"
#include "ethereum/ewm/BREthereumTransfer.h"

/**
*
Expand All @@ -46,6 +44,7 @@ struct BRCryptoTransferRecord {
uint64_t recv;
} btc;
struct {
BREthereumEWM ewm;
BREthereumTransfer tid;
BREthereumAddress accountAddress;
} eth;
Expand Down Expand Up @@ -199,10 +198,11 @@ cryptoTransferCreateAsETH (BRCryptoUnit unit,
BREthereumTransfer tid,
BRCryptoFeeBasis feeBasisEstimated) {
BRCryptoTransfer transfer = cryptoTransferCreateInternal (BLOCK_CHAIN_TYPE_ETH, unit, unitForFee);
transfer->u.eth.ewm = ewm;
transfer->u.eth.tid = tid;

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

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

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

transfer->feeBasisEstimated = (NULL == feeBasisEstimated
? cryptoFeeBasisCreateAsETH (unitForFee,
Expand Down Expand Up @@ -328,7 +328,8 @@ cryptoTransferGetAmountAsSign (BRCryptoTransfer transfer, BRCryptoBoolean isNega
}

case BLOCK_CHAIN_TYPE_ETH: {
BREthereumAmount ethAmount = transferGetAmount(transfer->u.eth.tid);
BREthereumAmount ethAmount = ewmTransferGetAmount (transfer->u.eth.ewm,
transfer->u.eth.tid);
switch (amountGetType(ethAmount)) {
case AMOUNT_ETHER:
amount = cryptoAmountCreate (transfer->unit,
Expand Down Expand Up @@ -509,10 +510,11 @@ cryptoTransferGetDirection (BRCryptoTransfer transfer) {
return CRYPTO_TRANSFER_RECEIVED;
}
case BLOCK_CHAIN_TYPE_ETH: {
BREthereumTransfer tid =transfer->u.eth.tid;
BREthereumEWM ewm = transfer->u.eth.ewm;
BREthereumTransfer tid = transfer->u.eth.tid;

BREthereumAddress source = transferGetSourceAddress (tid);
BREthereumAddress target = transferGetTargetAddress (tid);
BREthereumAddress source = ewmTransferGetSource (ewm, tid);
BREthereumAddress target = ewmTransferGetTarget (ewm, tid);

BREthereumBoolean accountIsSource = addressEqual (source, transfer->u.eth.accountAddress);
BREthereumBoolean accountIsTarget = addressEqual (target, transfer->u.eth.accountAddress);
Expand Down Expand Up @@ -563,9 +565,10 @@ cryptoTransferGetHash (BRCryptoTransfer transfer) {
: cryptoHashCreateAsBTC (hash));
}
case BLOCK_CHAIN_TYPE_ETH: {
BREthereumTransfer tid =transfer->u.eth.tid;
BREthereumEWM ewm = transfer->u.eth.ewm;
BREthereumTransfer tid = transfer->u.eth.tid;

BREthereumHash hash = transferGetOriginatingTransactionHash (tid);
BREthereumHash hash = ewmTransferGetOriginatingTransactionHash (ewm, tid);
return (ETHEREUM_BOOLEAN_TRUE == hashEqual(hash, hashCreateEmpty())
? NULL
: cryptoHashCreateAsETH (hash));
Expand Down
3 changes: 1 addition & 2 deletions crypto/BRCryptoWallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
#include "BRCryptoBase.h"
#include "BRCryptoPrivate.h"

#include "generic/BRGeneric.h"

#include "bitcoin/BRWallet.h"
#include "bitcoin/BRWalletManager.h"
#include "ethereum/BREthereum.h"
#include "ethereum/ewm/BREthereumTransfer.h"
#include "generic/BRGeneric.h"

/**
*
Expand Down
3 changes: 1 addition & 2 deletions crypto/BRCryptoWalletManagerClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "bitcoin/BRWalletManager.h"
#include "ethereum/BREthereum.h"
#include "ethereum/ewm/BREthereumTransfer.h"
#include "support/BRBase.h"
#include "support/BRSyncMode.h"

Expand Down Expand Up @@ -1280,7 +1279,7 @@ cwmTransactionEventAsETH (BREthereumClientContext context,

BRCryptoTransferState oldState = cryptoTransferGetState (transfer);

BREthereumFeeBasis ethFeeBasis = transferGetFeeBasis (tid);
BREthereumFeeBasis ethFeeBasis = ewmTransferGetFeeBasis (ewm, tid);

BRCryptoUnit unit = cryptoTransferGetUnitForFee(transfer);
BRCryptoFeeBasis feeBasisConfirmed = cryptoFeeBasisCreateAsETH (unit,
Expand Down
10 changes: 10 additions & 0 deletions ethereum/base/BREthereumFeeBasis.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ feeBasisCreate (BREthereumGas limit,
};
}

extern BREthereumGas
feeBasisGetGasLimit (BREthereumFeeBasis basis) {
return (FEE_BASIS_GAS == basis.type ? basis.u.gas.limit : gasCreate(0));
}

extern BREthereumGasPrice
feeBasisGetGasPrice (BREthereumFeeBasis basis) {
return (FEE_BASIS_GAS == basis.type ? basis.u.gas.price : gasPriceCreate(etherCreateZero()));
}

extern BREthereumEther
feeBasisGetFee (BREthereumFeeBasis feeBasis, int *overflow) { // BREthereumBoolean
*overflow = 0;
Expand Down
6 changes: 6 additions & 0 deletions ethereum/base/BREthereumFeeBasis.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ extern BREthereumFeeBasis
feeBasisCreate (BREthereumGas limit,
BREthereumGasPrice price);

extern BREthereumGas
feeBasisGetGasLimit (BREthereumFeeBasis basis);

extern BREthereumGasPrice
feeBasisGetGasPrice (BREthereumFeeBasis basis);

extern BREthereumEther
feeBasisGetFee (BREthereumFeeBasis feeBasis, int *overflow);

Expand Down
Loading