Skip to content

Commit

Permalink
Merge pull request #1718 from jonjove/asset-backed-offers
Browse files Browse the repository at this point in the history
Asset backed offers

Reviewed-by: vogel
  • Loading branch information
latobarita authored Aug 2, 2018
2 parents ce5e5d1 + 3c9dfc0 commit 4dab962
Show file tree
Hide file tree
Showing 52 changed files with 6,704 additions and 726 deletions.
9 changes: 5 additions & 4 deletions Builds/VisualStudio/stellar-core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ exit /b 0
<ClCompile Include="..\..\src\invariant\InvariantTests.cpp" />
<ClCompile Include="..\..\src\invariant\InvariantTestUtils.cpp" />
<ClCompile Include="..\..\src\invariant\LedgerEntryIsValid.cpp" />
<ClCompile Include="..\..\src\invariant\MinimumAccountBalance.cpp" />
<ClCompile Include="..\..\src\invariant\MinimumAccountBalanceTests.cpp" />
<ClCompile Include="..\..\src\invariant\LiabilitiesMatchOffers.cpp" />
<ClCompile Include="..\..\src\invariant\LiabilitiesMatchOffersTests.cpp" />
<ClCompile Include="..\..\src\ledger\AccountFrame.cpp" />
<ClCompile Include="..\..\src\ledger\CheckpointRange.cpp" />
<ClCompile Include="..\..\src\ledger\DataFrame.cpp" />
Expand All @@ -346,6 +346,7 @@ exit /b 0
<ClCompile Include="..\..\src\ledger\LedgerRange.cpp" />
<ClCompile Include="..\..\src\ledger\LedgerTests.cpp" />
<ClCompile Include="..\..\src\ledger\LedgerTestUtils.cpp" />
<ClCompile Include="..\..\src\ledger\LiabilitiesTests.cpp" />
<ClCompile Include="..\..\src\ledger\OfferFrame.cpp" />
<ClCompile Include="..\..\src\ledger\SyncingLedgerChain.cpp" />
<ClCompile Include="..\..\src\ledger\SyncingLedgerChainTests.cpp" />
Expand Down Expand Up @@ -601,7 +602,7 @@ exit /b 0
<ClInclude Include="..\..\src\invariant\InvariantManagerImpl.h" />
<ClInclude Include="..\..\src\invariant\InvariantTestUtils.h" />
<ClInclude Include="..\..\src\invariant\LedgerEntryIsValid.h" />
<ClInclude Include="..\..\src\invariant\MinimumAccountBalance.h" />
<ClCompile Include="..\..\src\invariant\LiabilitiesMatchOffers.h" />
<ClInclude Include="..\..\src\ledger\CheckpointRange.h" />
<ClInclude Include="..\..\src\ledger\DataFrame.h" />
<ClInclude Include="..\..\src\ledger\LedgerRange.h" />
Expand Down Expand Up @@ -927,4 +928,4 @@ exit /b 0
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
16 changes: 16 additions & 0 deletions docs/db-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ homedomain | VARCHAR(32) |
thresholds | TEXT | (BASE64)
flags | INT NOT NULL |
lastmodified | INT NOT NULL | lastModifiedLedgerSeq
buyingliabilities | BIGINT CHECK (buyingliabilities >= 0)
sellingliabilities | BIGINT CHECK (sellingliabilities >= 0)

## offers

Expand Down Expand Up @@ -92,6 +94,8 @@ tlimit | BIGINT NOT NULL DEFAULT 0 CHECK (tlimit >= 0) | limit
balance | BIGINT NOT NULL DEFAULT 0 CHECK (balance >= 0) |
flags | INT NOT NULL |
lastmodified | INT NOT NULL | lastModifiedLedgerSeq
buyingliabilities | BIGINT CHECK (buyingliabilities >= 0)
sellingliabilities | BIGINT CHECK (sellingliabilities >= 0)


## txhistory
Expand Down Expand Up @@ -154,3 +158,15 @@ port | INT DEFAULT 0 CHECK (port > 0 AND port <= 65535) NOT NULL |
nextattempt | TIMESTAMP NOT NULL |
numfailures | INT DEFAULT 0 CHECK (numfailures >= 0) NOT NULL |


## upgradehistory

Defined in [`src/herder/Upgrades.cpp`](/src/herder/Upgrades.cpp)

Field | Type | Description
------|------|---------------
ledgerseq | INT NOT NULL CHECK (ledgerseq >= 0) | Ledger this upgrade got applied
upgradeindex | INT NOT NULL | Apply order (per ledger, 1)
upgrade | TEXT NOT NULL | The upgrade (XDR)
changes | TEXT NOT NULL | LedgerEntryChanges (XDR)

8 changes: 4 additions & 4 deletions docs/stellar-core_example.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,11 @@ RUN_STANDALONE=false
# valid.
# The overhead may cause slower systems to not perform as fast as the rest
# of the network, caution is advised when using this.
# - "MinimumAccountBalance"
# - "LiabilitiesMatchOffers"
# Setting this will cause additional work on each operation apply - it
# checks that accounts that have had their balance decrease satisfy the
# minimum balance requirement. For additional information see the comment
# in the header invariant/MinimumAccountBalance.h.
# checks that accounts, trust lines, and offers satisfy all constraints
# associated with liabilities. For additional information, see the comment
# in the header invariant/LiabilitiesMatchOffers.h.
# The overhead may cause slower systems to not perform as fast as the rest
# of the network, caution is advised when using this.
INVARIANT_CHECKS = []
Expand Down
17 changes: 16 additions & 1 deletion src/database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "bucket/BucketManager.h"
#include "herder/HerderPersistence.h"
#include "herder/Upgrades.h"
#include "history/HistoryManager.h"
#include "ledger/AccountFrame.h"
#include "ledger/DataFrame.h"
Expand Down Expand Up @@ -53,7 +54,7 @@ using namespace std;

bool Database::gDriversRegistered = false;

static unsigned long const SCHEMA_VERSION = 6;
static unsigned long const SCHEMA_VERSION = 7;

static void
setSerializable(soci::session& sess)
Expand Down Expand Up @@ -140,9 +141,23 @@ Database::applySchemaUpgrade(unsigned long vers)
}
}
break;

case 6:
mSession << "ALTER TABLE peers ADD flags INT NOT NULL DEFAULT 0";
break;

case 7:
Upgrades::dropAll(*this);
mSession << "ALTER TABLE accounts ADD buyingliabilities BIGINT "
"CHECK (buyingliabilities >= 0)";
mSession << "ALTER TABLE accounts ADD sellingliabilities BIGINT "
"CHECK (sellingliabilities >= 0)";
mSession << "ALTER TABLE trustlines ADD buyingliabilities BIGINT "
"CHECK (buyingliabilities >= 0)";
mSession << "ALTER TABLE trustlines ADD sellingliabilities BIGINT "
"CHECK (sellingliabilities >= 0)";
break;

default:
throw std::runtime_error("Unknown DB schema version");
break;
Expand Down
2 changes: 1 addition & 1 deletion src/herder/HerderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ HerderImpl::recvTransaction(TransactionFramePtr tx)
return TX_STATUS_ERROR;
}

if (tx->getSourceAccount().getBalanceAboveReserve(mLedgerManager) < totFee)
if (tx->getSourceAccount().getAvailableBalance(mLedgerManager) < totFee)
{
tx->getResult().result.code(txINSUFFICIENT_BALANCE);
return TX_STATUS_ERROR;
Expand Down
6 changes: 2 additions & 4 deletions src/herder/TxSetFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,8 @@ TxSetFrame::checkOrTrim(
if (lastTx)
{
// make sure account can pay the fee for all these tx
int64_t newBalance =
lastTx->getSourceAccount().getBalance() - totFee;
if (newBalance < lastTx->getSourceAccount().getMinimumBalance(
app.getLedgerManager()))
auto const& source = lastTx->getSourceAccount();
if (source.getAvailableBalance(app.getLedgerManager()) < totFee)
{
if (!processInsufficientBalance(item.second))
return false;
Expand Down
Loading

0 comments on commit 4dab962

Please sign in to comment.