Skip to content

Commit

Permalink
Add "Default Ripple" account flag and associated logic:
Browse files Browse the repository at this point in the history
AccountSet set/clear, asfDefaultRipple = 8

AccountRoot flag, lsfDefaultRipple = 0x00800000

In trustCreate, set no ripple flag if appropriate.

If an account does not have the default ripple flag set,
new ripple lines created as a result of its offers being
taken or people creating trust lines to it have no ripple
set by that account's side automatically

Trust lines can be deleted if the no ripple flag matches
its default setting based on the account's default ripple
setting.

Fix default no-rippling in integration tests.
  • Loading branch information
JoelKatz authored and nbougalis committed Mar 10, 2015
1 parent 9cc8eec commit e9381dd
Show file tree
Hide file tree
Showing 13 changed files with 287 additions and 126 deletions.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"name": "rippled",
"version": "0.0.1",
"description": "Rippled Server",

"private": true,

"directories": {
"test": "test"
},

"dependencies": {
"ripple-lib": "0.8.2",
"async": "~0.2.9",
Expand All @@ -17,18 +14,16 @@
"deep-equal": "0.0.0"
},
"devDependencies": {
"assert-diff": "^1.0.1",
"coffee-script": "~1.6.3",
"mocha": "~1.13.0"
},

"scripts": {
"test": "mocha test/websocket-test.js test/server-test.js test/*-test.{js,coffee}"
},

"repository": {
"type": "git",
"url": "git://github.com/ripple/rippled.git"
},

"readmeFilename": "README.md"
}
16 changes: 15 additions & 1 deletion src/ripple/app/ledger/LedgerEntrySet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,12 @@ TER LedgerEntrySet::trustCreate (
const bool bSetDst = saLimit.getIssuer () == uDstAccountID;
const bool bSetHigh = bSrcHigh ^ bSetDst;

assert (sleAccount->getFieldAccount160 (sfAccount) ==
(bSetHigh ? uHighAccountID : uLowAccountID));
SLE::pointer slePeer = entryCache (ltACCOUNT_ROOT,
getAccountRootIndex (bSetHigh ? uLowAccountID : uHighAccountID));
assert (slePeer);

// Remember deletion hints.
sleRippleState->setFieldU64 (sfLowNode, uLowNode);
sleRippleState->setFieldU64 (sfHighNode, uHighNode);
Expand Down Expand Up @@ -1376,6 +1382,12 @@ TER LedgerEntrySet::trustCreate (
uFlags |= (!bSetHigh ? lsfLowFreeze : lsfHighFreeze);
}

if ((slePeer->getFlags() & lsfDefaultRipple) == 0)
{
// The other side's default is no rippling
uFlags |= (bSetHigh ? lsfLowNoRipple : lsfHighNoRipple);
}

sleRippleState->setFieldU32 (sfFlags, uFlags);
incrementOwnerCount (sleAccount);

Expand Down Expand Up @@ -1507,7 +1519,9 @@ TER LedgerEntrySet::rippleCredit (
// Sender is zero or negative.
&& (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve))
// Sender reserve is set.
&& !(uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple))
&& static_cast <bool> (uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) !=
static_cast <bool> (entryCache (ltACCOUNT_ROOT,
getAccountRootIndex (uSenderID))->getFlags() & lsfDefaultRipple)
&& !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze))
&& !sleRippleState->getFieldAmount (
!bSenderHigh ? sfLowLimit : sfHighLimit)
Expand Down
9 changes: 9 additions & 0 deletions src/ripple/app/transactors/SetAccount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,15 @@ class SetAccount
uFlagsOut &= ~lsfDisableMaster;
}

if (uSetFlag == asfDefaultRipple)
{
uFlagsOut |= lsfDefaultRipple;
}
else if (uClearFlag == asfDefaultRipple)
{
uFlagsOut &= ~lsfDefaultRipple;
}

if (uSetFlag == asfNoFreeze)
{
m_journal.trace << "Set NoFreeze flag";
Expand Down
6 changes: 4 additions & 2 deletions src/ripple/app/transactors/SetTrust.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,17 @@ class SetTrust

if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0;

bool const bLowDefRipple = sleLowAccount->getFlags() & lsfDefaultRipple;
bool const bHighDefRipple = sleHighAccount->getFlags() & lsfDefaultRipple;

bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
(uFlagsOut & lsfLowNoRipple) ||
((uFlagsOut & lsfLowNoRipple) == 0) != bLowDefRipple ||
(uFlagsOut & lsfLowFreeze) ||
saLowLimit || saLowBalance > zero;
bool const bLowReserveClear = !bLowReserveSet;

bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
(uFlagsOut & lsfHighNoRipple) ||
((uFlagsOut & lsfHighNoRipple) == 0) != bHighDefRipple ||
(uFlagsOut & lsfHighFreeze) ||
saHighLimit || saHighBalance > zero;
bool const bHighReserveClear = !bHighReserveSet;
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/LedgerFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ enum LedgerSpecificFlags
lsfDisableMaster = 0x00100000, // True, force regular key
lsfNoFreeze = 0x00200000, // True, cannot freeze ripple states
lsfGlobalFreeze = 0x00400000, // True, all assets frozen
lsfDefaultRipple = 0x00800000, // True, trust lines allow rippling by default

// ltOFFER
lsfPassive = 0x00010000,
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/TxFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const std::uint32_t asfDisableMaster = 4;
const std::uint32_t asfAccountTxnID = 5;
const std::uint32_t asfNoFreeze = 6;
const std::uint32_t asfGlobalFreeze = 7;
const std::uint32_t asfDefaultRipple = 8;

// OfferCreate flags:
const std::uint32_t tfPassive = 0x00010000;
Expand Down
2 changes: 1 addition & 1 deletion test/freeze-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,4 @@ execute_if_enabled (suite, enforced) ->

remote.request_account_offers args, (err, res) ->
assert res.offers.length == 0
done()
done()
10 changes: 9 additions & 1 deletion test/ledger-state.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,9 @@ exports.LedgerState = class LedgerState

add_transaction_fees: ->
extra_fees = {}
account_sets = ([k] for k,ac of @accounts)
fee = Amount.from_json(@remote.fee_cushion * 10)
for list in [@trusts, @iou_payments, @offers]
for list in [@trusts, @iou_payments, @offers, account_sets]
for [src, args...] in list
extra = extra_fees[src]
extra = if extra? then extra.add(fee) else fee
Expand Down Expand Up @@ -532,6 +533,13 @@ exports.LedgerState = class LedgerState
LOG("Account `#{src}` creating account `#{dest}` by "+
"making payment of #{amt.to_text_full()}") ),
cb)
(cb) ->
reqs.transactor(
Transaction::account_set,
accounts_apply_arguments,
((account, tx) ->
tx.tx_json.SetFlag = 8
), cb)
(cb) ->
reqs.transactor(
Transaction::ripple_line_set,
Expand Down
89 changes: 89 additions & 0 deletions test/no-ripple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,92 @@ suite('NoRipple', function() {
});
});
});

suite('Default ripple', function() {
var $ = { };

setup(function(done) {
testutils.build_setup().call($, done);
});

teardown(function(done) {
testutils.build_teardown().call($, done);
});

test('Set default ripple on account, check new trustline', function(done) {
var steps = [
function (callback) {
testutils.create_accounts(
$.remote,
'root',
'10000.0',
[ 'alice', 'bob' ],
{ default_rippling: false },
callback);
},
function (callback) {
var tx = $.remote.createTransaction('AccountSet', {
account: 'bob',
set_flag: 8
});
testutils.submit_transaction(tx, callback);
},
function (callback) {
var tx = $.remote.createTransaction('TrustSet', {
account: 'root',
limit: '100/USD/alice'
});
testutils.submit_transaction(tx, callback);
},
function (callback) {
var tx = $.remote.createTransaction('TrustSet', {
account: 'root',
limit: '100/USD/bob'
});
testutils.submit_transaction(tx, callback);
},
function (callback) {
$.remote.requestAccountLines({ account: 'root', peer: 'alice' }, function(err, m) {
assert.ifError(err);
assert(Array.isArray(m.lines));
assert(m.lines[0].no_ripple_peer,
'Trustline should have no_ripple_peer set');
callback();
});
},
function (callback) {
$.remote.requestAccountLines({ account: 'alice', peer: 'root' }, function(err, m) {
assert.ifError(err);
assert(Array.isArray(m.lines));
assert(m.lines[0].no_ripple,
'Trustline should have no_ripple set');
callback();
});
},
function (callback) {
$.remote.requestAccountLines({ account: 'root', peer: 'bob' }, function(err, m) {
assert.ifError(err);
assert(Array.isArray(m.lines));
assert(!m.lines[0].no_ripple,
'Trustline should not have no_ripple set');
callback();
});
},
function (callback) {
$.remote.requestAccountLines({ account: 'bob', peer: 'root' }, function(err, m) {
assert.ifError(err);
assert(Array.isArray(m.lines));
assert(!m.lines[0].no_ripple_peer,
'Trustline should not have no_ripple_peer set');
callback();
});
}
]

async.series(steps, function(error) {
assert(!error, error);
done();
});
});

});
29 changes: 16 additions & 13 deletions test/offer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ suite("Client Issue #535", function() {
var starting_xrp = $.amount_for({
ledger_entries: 1,
default_transactions: 2,
extra: '100.0'
extra: '100.1'
});

testutils.create_accounts($.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback);
Expand Down Expand Up @@ -1938,12 +1938,16 @@ suite("Client Issue #535", function() {

$.remote.transaction()
.offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox")
.on('submitted', function (m) {
// console.log("proposed: offer_create: %s", json.stringify(m));
callback(m.engine_result !== 'tesSUCCESS');
.on('submitted', function(m) {
if (m.engine_result === 'tesSUCCESS') {
callback();
} else {
// console.log("proposed: %s", JSON.stringify(m, undefined, 2));
callback(m);
}

seq_carol = m.tx_json.sequence;
})
seq_carol = m.tx_json.sequence;
})
.submit();
},
function (callback) {
Expand Down Expand Up @@ -1982,13 +1986,12 @@ suite("Client Issue #535", function() {
},
callback);
},
], function (error) {
if (error)
//console.log("result: %s: error=%s", self.what, error);
assert(!error, self.what);

done();
});
], function (error) {
if (error)
//console.log("result: %s: error=%s", self.what, error);
assert(!error, self.what);
done();
});
});
});
// vim:sw=2:sts=2:ts=8:et
Loading

0 comments on commit e9381dd

Please sign in to comment.