Skip to content

Commit e9381dd

Browse files
JoelKatznbougalis
authored andcommitted
Add "Default Ripple" account flag and associated logic:
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.
1 parent 9cc8eec commit e9381dd

File tree

13 files changed

+287
-126
lines changed

13 files changed

+287
-126
lines changed

package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
"name": "rippled",
33
"version": "0.0.1",
44
"description": "Rippled Server",
5-
65
"private": true,
7-
86
"directories": {
97
"test": "test"
108
},
11-
129
"dependencies": {
1310
"ripple-lib": "0.8.2",
1411
"async": "~0.2.9",
@@ -17,18 +14,16 @@
1714
"deep-equal": "0.0.0"
1815
},
1916
"devDependencies": {
17+
"assert-diff": "^1.0.1",
2018
"coffee-script": "~1.6.3",
2119
"mocha": "~1.13.0"
2220
},
23-
2421
"scripts": {
2522
"test": "mocha test/websocket-test.js test/server-test.js test/*-test.{js,coffee}"
2623
},
27-
2824
"repository": {
2925
"type": "git",
3026
"url": "git://github.com/ripple/rippled.git"
3127
},
32-
3328
"readmeFilename": "README.md"
3429
}

src/ripple/app/ledger/LedgerEntrySet.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,12 @@ TER LedgerEntrySet::trustCreate (
13421342
const bool bSetDst = saLimit.getIssuer () == uDstAccountID;
13431343
const bool bSetHigh = bSrcHigh ^ bSetDst;
13441344

1345+
assert (sleAccount->getFieldAccount160 (sfAccount) ==
1346+
(bSetHigh ? uHighAccountID : uLowAccountID));
1347+
SLE::pointer slePeer = entryCache (ltACCOUNT_ROOT,
1348+
getAccountRootIndex (bSetHigh ? uLowAccountID : uHighAccountID));
1349+
assert (slePeer);
1350+
13451351
// Remember deletion hints.
13461352
sleRippleState->setFieldU64 (sfLowNode, uLowNode);
13471353
sleRippleState->setFieldU64 (sfHighNode, uHighNode);
@@ -1376,6 +1382,12 @@ TER LedgerEntrySet::trustCreate (
13761382
uFlags |= (!bSetHigh ? lsfLowFreeze : lsfHighFreeze);
13771383
}
13781384

1385+
if ((slePeer->getFlags() & lsfDefaultRipple) == 0)
1386+
{
1387+
// The other side's default is no rippling
1388+
uFlags |= (bSetHigh ? lsfLowNoRipple : lsfHighNoRipple);
1389+
}
1390+
13791391
sleRippleState->setFieldU32 (sfFlags, uFlags);
13801392
incrementOwnerCount (sleAccount);
13811393

@@ -1507,7 +1519,9 @@ TER LedgerEntrySet::rippleCredit (
15071519
// Sender is zero or negative.
15081520
&& (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve))
15091521
// Sender reserve is set.
1510-
&& !(uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple))
1522+
&& static_cast <bool> (uFlags & (!bSenderHigh ? lsfLowNoRipple : lsfHighNoRipple)) !=
1523+
static_cast <bool> (entryCache (ltACCOUNT_ROOT,
1524+
getAccountRootIndex (uSenderID))->getFlags() & lsfDefaultRipple)
15111525
&& !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze))
15121526
&& !sleRippleState->getFieldAmount (
15131527
!bSenderHigh ? sfLowLimit : sfHighLimit)

src/ripple/app/transactors/SetAccount.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ class SetAccount
168168
uFlagsOut &= ~lsfDisableMaster;
169169
}
170170

171+
if (uSetFlag == asfDefaultRipple)
172+
{
173+
uFlagsOut |= lsfDefaultRipple;
174+
}
175+
else if (uClearFlag == asfDefaultRipple)
176+
{
177+
uFlagsOut &= ~lsfDefaultRipple;
178+
}
179+
171180
if (uSetFlag == asfNoFreeze)
172181
{
173182
m_journal.trace << "Set NoFreeze flag";

src/ripple/app/transactors/SetTrust.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,17 @@ class SetTrust
288288

289289
if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0;
290290

291+
bool const bLowDefRipple = sleLowAccount->getFlags() & lsfDefaultRipple;
292+
bool const bHighDefRipple = sleHighAccount->getFlags() & lsfDefaultRipple;
291293

292294
bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
293-
(uFlagsOut & lsfLowNoRipple) ||
295+
((uFlagsOut & lsfLowNoRipple) == 0) != bLowDefRipple ||
294296
(uFlagsOut & lsfLowFreeze) ||
295297
saLowLimit || saLowBalance > zero;
296298
bool const bLowReserveClear = !bLowReserveSet;
297299

298300
bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
299-
(uFlagsOut & lsfHighNoRipple) ||
301+
((uFlagsOut & lsfHighNoRipple) == 0) != bHighDefRipple ||
300302
(uFlagsOut & lsfHighFreeze) ||
301303
saHighLimit || saHighBalance > zero;
302304
bool const bHighReserveClear = !bHighReserveSet;

src/ripple/protocol/LedgerFormats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ enum LedgerSpecificFlags
111111
lsfDisableMaster = 0x00100000, // True, force regular key
112112
lsfNoFreeze = 0x00200000, // True, cannot freeze ripple states
113113
lsfGlobalFreeze = 0x00400000, // True, all assets frozen
114+
lsfDefaultRipple = 0x00800000, // True, trust lines allow rippling by default
114115

115116
// ltOFFER
116117
lsfPassive = 0x00010000,

src/ripple/protocol/TxFlags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const std::uint32_t asfDisableMaster = 4;
6565
const std::uint32_t asfAccountTxnID = 5;
6666
const std::uint32_t asfNoFreeze = 6;
6767
const std::uint32_t asfGlobalFreeze = 7;
68+
const std::uint32_t asfDefaultRipple = 8;
6869

6970
// OfferCreate flags:
7071
const std::uint32_t tfPassive = 0x00010000;

test/freeze-test.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,4 +847,4 @@ execute_if_enabled (suite, enforced) ->
847847

848848
remote.request_account_offers args, (err, res) ->
849849
assert res.offers.length == 0
850-
done()
850+
done()

test/ledger-state.coffee

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,9 @@ exports.LedgerState = class LedgerState
497497

498498
add_transaction_fees: ->
499499
extra_fees = {}
500+
account_sets = ([k] for k,ac of @accounts)
500501
fee = Amount.from_json(@remote.fee_cushion * 10)
501-
for list in [@trusts, @iou_payments, @offers]
502+
for list in [@trusts, @iou_payments, @offers, account_sets]
502503
for [src, args...] in list
503504
extra = extra_fees[src]
504505
extra = if extra? then extra.add(fee) else fee
@@ -532,6 +533,13 @@ exports.LedgerState = class LedgerState
532533
LOG("Account `#{src}` creating account `#{dest}` by "+
533534
"making payment of #{amt.to_text_full()}") ),
534535
cb)
536+
(cb) ->
537+
reqs.transactor(
538+
Transaction::account_set,
539+
accounts_apply_arguments,
540+
((account, tx) ->
541+
tx.tx_json.SetFlag = 8
542+
), cb)
535543
(cb) ->
536544
reqs.transactor(
537545
Transaction::ripple_line_set,

test/no-ripple-test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,92 @@ suite('NoRipple', function() {
326326
});
327327
});
328328
});
329+
330+
suite('Default ripple', function() {
331+
var $ = { };
332+
333+
setup(function(done) {
334+
testutils.build_setup().call($, done);
335+
});
336+
337+
teardown(function(done) {
338+
testutils.build_teardown().call($, done);
339+
});
340+
341+
test('Set default ripple on account, check new trustline', function(done) {
342+
var steps = [
343+
function (callback) {
344+
testutils.create_accounts(
345+
$.remote,
346+
'root',
347+
'10000.0',
348+
[ 'alice', 'bob' ],
349+
{ default_rippling: false },
350+
callback);
351+
},
352+
function (callback) {
353+
var tx = $.remote.createTransaction('AccountSet', {
354+
account: 'bob',
355+
set_flag: 8
356+
});
357+
testutils.submit_transaction(tx, callback);
358+
},
359+
function (callback) {
360+
var tx = $.remote.createTransaction('TrustSet', {
361+
account: 'root',
362+
limit: '100/USD/alice'
363+
});
364+
testutils.submit_transaction(tx, callback);
365+
},
366+
function (callback) {
367+
var tx = $.remote.createTransaction('TrustSet', {
368+
account: 'root',
369+
limit: '100/USD/bob'
370+
});
371+
testutils.submit_transaction(tx, callback);
372+
},
373+
function (callback) {
374+
$.remote.requestAccountLines({ account: 'root', peer: 'alice' }, function(err, m) {
375+
assert.ifError(err);
376+
assert(Array.isArray(m.lines));
377+
assert(m.lines[0].no_ripple_peer,
378+
'Trustline should have no_ripple_peer set');
379+
callback();
380+
});
381+
},
382+
function (callback) {
383+
$.remote.requestAccountLines({ account: 'alice', peer: 'root' }, function(err, m) {
384+
assert.ifError(err);
385+
assert(Array.isArray(m.lines));
386+
assert(m.lines[0].no_ripple,
387+
'Trustline should have no_ripple set');
388+
callback();
389+
});
390+
},
391+
function (callback) {
392+
$.remote.requestAccountLines({ account: 'root', peer: 'bob' }, function(err, m) {
393+
assert.ifError(err);
394+
assert(Array.isArray(m.lines));
395+
assert(!m.lines[0].no_ripple,
396+
'Trustline should not have no_ripple set');
397+
callback();
398+
});
399+
},
400+
function (callback) {
401+
$.remote.requestAccountLines({ account: 'bob', peer: 'root' }, function(err, m) {
402+
assert.ifError(err);
403+
assert(Array.isArray(m.lines));
404+
assert(!m.lines[0].no_ripple_peer,
405+
'Trustline should not have no_ripple_peer set');
406+
callback();
407+
});
408+
}
409+
]
410+
411+
async.series(steps, function(error) {
412+
assert(!error, error);
413+
done();
414+
});
415+
});
416+
417+
});

test/offer-test.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ suite("Client Issue #535", function() {
19091909
var starting_xrp = $.amount_for({
19101910
ledger_entries: 1,
19111911
default_transactions: 2,
1912-
extra: '100.0'
1912+
extra: '100.1'
19131913
});
19141914

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

19391939
$.remote.transaction()
19401940
.offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox")
1941-
.on('submitted', function (m) {
1942-
// console.log("proposed: offer_create: %s", json.stringify(m));
1943-
callback(m.engine_result !== 'tesSUCCESS');
1941+
.on('submitted', function(m) {
1942+
if (m.engine_result === 'tesSUCCESS') {
1943+
callback();
1944+
} else {
1945+
// console.log("proposed: %s", JSON.stringify(m, undefined, 2));
1946+
callback(m);
1947+
}
19441948

1945-
seq_carol = m.tx_json.sequence;
1946-
})
1949+
seq_carol = m.tx_json.sequence;
1950+
})
19471951
.submit();
19481952
},
19491953
function (callback) {
@@ -1982,13 +1986,12 @@ suite("Client Issue #535", function() {
19821986
},
19831987
callback);
19841988
},
1985-
], function (error) {
1986-
if (error)
1987-
//console.log("result: %s: error=%s", self.what, error);
1988-
assert(!error, self.what);
1989-
1990-
done();
1991-
});
1989+
], function (error) {
1990+
if (error)
1991+
//console.log("result: %s: error=%s", self.what, error);
1992+
assert(!error, self.what);
1993+
done();
1994+
});
19921995
});
19931996
});
19941997
// vim:sw=2:sts=2:ts=8:et

0 commit comments

Comments
 (0)