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.
This commit is contained in:
David Schwartz
2015-03-09 13:43:58 -07:00
committed by Tom Ritchford
parent 6c364f63cc
commit 3b3b897193
13 changed files with 244 additions and 75 deletions

View File

@@ -7,7 +7,6 @@
"test": "test" "test": "test"
}, },
"dependencies": { "dependencies": {
"assert-diff": "0.0.4",
"async": "~0.2.9", "async": "~0.2.9",
"deep-equal": "0.0.0", "deep-equal": "0.0.0",
"extend": "~1.2.0", "extend": "~1.2.0",
@@ -16,6 +15,7 @@
"simple-jsonrpc": "~0.0.2" "simple-jsonrpc": "~0.0.2"
}, },
"devDependencies": { "devDependencies": {
"assert-diff": "^1.0.1",
"coffee-script": "^1.8.0", "coffee-script": "^1.8.0",
"mocha": "^2.1.0" "mocha": "^2.1.0"
}, },

View File

@@ -1309,6 +1309,12 @@ TER LedgerEntrySet::trustCreate (
const bool bSetDst = saLimit.getIssuer () == uDstAccountID; const bool bSetDst = saLimit.getIssuer () == uDstAccountID;
const bool bSetHigh = bSrcHigh ^ bSetDst; 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. // Remember deletion hints.
sleRippleState->setFieldU64 (sfLowNode, uLowNode); sleRippleState->setFieldU64 (sfLowNode, uLowNode);
sleRippleState->setFieldU64 (sfHighNode, uHighNode); sleRippleState->setFieldU64 (sfHighNode, uHighNode);
@@ -1343,6 +1349,12 @@ TER LedgerEntrySet::trustCreate (
uFlags |= (!bSetHigh ? lsfLowFreeze : lsfHighFreeze); 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); sleRippleState->setFieldU32 (sfFlags, uFlags);
incrementOwnerCount (sleAccount); incrementOwnerCount (sleAccount);
@@ -1474,7 +1486,9 @@ TER LedgerEntrySet::rippleCredit (
// Sender is zero or negative. // Sender is zero or negative.
&& (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve)) && (uFlags & (!bSenderHigh ? lsfLowReserve : lsfHighReserve))
// Sender reserve is set. // 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)) && !(uFlags & (!bSenderHigh ? lsfLowFreeze : lsfHighFreeze))
&& !sleRippleState->getFieldAmount ( && !sleRippleState->getFieldAmount (
!bSenderHigh ? sfLowLimit : sfHighLimit) !bSenderHigh ? sfLowLimit : sfHighLimit)

View File

@@ -174,6 +174,15 @@ public:
uFlagsOut &= ~lsfDisableMaster; uFlagsOut &= ~lsfDisableMaster;
} }
if (uSetFlag == asfDefaultRipple)
{
uFlagsOut |= lsfDefaultRipple;
}
else if (uClearFlag == asfDefaultRipple)
{
uFlagsOut &= ~lsfDefaultRipple;
}
if (uSetFlag == asfNoFreeze) if (uSetFlag == asfNoFreeze)
{ {
if (!mSigMaster && !(uFlagsIn & lsfDisableMaster)) if (!mSigMaster && !(uFlagsIn & lsfDisableMaster))

View File

@@ -288,15 +288,17 @@ public:
if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0; if (QUALITY_ONE == uHighQualityOut) uHighQualityOut = 0;
bool const bLowDefRipple = sleLowAccount->getFlags() & lsfDefaultRipple;
bool const bHighDefRipple = sleHighAccount->getFlags() & lsfDefaultRipple;
bool const bLowReserveSet = uLowQualityIn || uLowQualityOut || bool const bLowReserveSet = uLowQualityIn || uLowQualityOut ||
(uFlagsOut & lsfLowNoRipple) || ((uFlagsOut & lsfLowNoRipple) == 0) != bLowDefRipple ||
(uFlagsOut & lsfLowFreeze) || (uFlagsOut & lsfLowFreeze) ||
saLowLimit || saLowBalance > zero; saLowLimit || saLowBalance > zero;
bool const bLowReserveClear = !bLowReserveSet; bool const bLowReserveClear = !bLowReserveSet;
bool const bHighReserveSet = uHighQualityIn || uHighQualityOut || bool const bHighReserveSet = uHighQualityIn || uHighQualityOut ||
(uFlagsOut & lsfHighNoRipple) || ((uFlagsOut & lsfHighNoRipple) == 0) != bHighDefRipple ||
(uFlagsOut & lsfHighFreeze) || (uFlagsOut & lsfHighFreeze) ||
saHighLimit || saHighBalance > zero; saHighLimit || saHighBalance > zero;
bool const bHighReserveClear = !bHighReserveSet; bool const bHighReserveClear = !bHighReserveSet;

View File

@@ -111,6 +111,7 @@ enum LedgerSpecificFlags
lsfDisableMaster = 0x00100000, // True, force regular key lsfDisableMaster = 0x00100000, // True, force regular key
lsfNoFreeze = 0x00200000, // True, cannot freeze ripple states lsfNoFreeze = 0x00200000, // True, cannot freeze ripple states
lsfGlobalFreeze = 0x00400000, // True, all assets frozen lsfGlobalFreeze = 0x00400000, // True, all assets frozen
lsfDefaultRipple = 0x00800000, // True, trust lines allow rippling by default
// ltOFFER // ltOFFER
lsfPassive = 0x00010000, lsfPassive = 0x00010000,

View File

@@ -65,6 +65,7 @@ const std::uint32_t asfDisableMaster = 4;
const std::uint32_t asfAccountTxnID = 5; const std::uint32_t asfAccountTxnID = 5;
const std::uint32_t asfNoFreeze = 6; const std::uint32_t asfNoFreeze = 6;
const std::uint32_t asfGlobalFreeze = 7; const std::uint32_t asfGlobalFreeze = 7;
const std::uint32_t asfDefaultRipple = 8;
// OfferCreate flags: // OfferCreate flags:
const std::uint32_t tfPassive = 0x00010000; const std::uint32_t tfPassive = 0x00010000;

View File

@@ -848,4 +848,4 @@ execute_if_enabled (suite, enforced) ->
remote.request_account_offers args, (err, res) -> remote.request_account_offers args, (err, res) ->
assert res.offers.length == 0 assert res.offers.length == 0
done() done()

View File

@@ -491,8 +491,9 @@ exports.LedgerState = class LedgerState
add_transaction_fees: -> add_transaction_fees: ->
extra_fees = {} extra_fees = {}
account_sets = ([k] for k,ac of @accounts)
fee = Amount.from_json(@remote.fee_cushion * 10) 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 for [src, args...] in list
extra = extra_fees[src] extra = extra_fees[src]
extra = if extra? then extra.add(fee) else fee extra = if extra? then extra.add(fee) else fee
@@ -526,6 +527,13 @@ exports.LedgerState = class LedgerState
LOG("Account `#{src}` creating account `#{dest}` by "+ LOG("Account `#{src}` creating account `#{dest}` by "+
"making payment of #{amt.to_text_full()}") ), "making payment of #{amt.to_text_full()}") ),
cb) cb)
(cb) ->
reqs.transactor(
Transaction::account_set,
accounts_apply_arguments,
((account, tx) ->
tx.tx_json.SetFlag = 8
), cb)
(cb) -> (cb) ->
reqs.transactor( reqs.transactor(
Transaction::ripple_line_set, Transaction::ripple_line_set,

View File

@@ -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();
});
});
});

View File

@@ -1909,7 +1909,7 @@ suite("Client Issue #535", function() {
var starting_xrp = $.amount_for({ var starting_xrp = $.amount_for({
ledger_entries: 1, ledger_entries: 1,
default_transactions: 2, default_transactions: 2,
extra: '100.0' extra: '100.1'
}); });
testutils.create_accounts($.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback); testutils.create_accounts($.remote, "root", starting_xrp, ["alice", "bob", "mtgox"], callback);
@@ -1938,12 +1938,16 @@ suite("Client Issue #535", function() {
$.remote.transaction() $.remote.transaction()
.offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox") .offer_create("alice", "100/XTS/mtgox", "100/XXX/mtgox")
.on('submitted', function (m) { .on('submitted', function(m) {
// console.log("proposed: offer_create: %s", json.stringify(m)); if (m.engine_result === 'tesSUCCESS') {
callback(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(); .submit();
}, },
function (callback) { function (callback) {
@@ -1982,13 +1986,12 @@ suite("Client Issue #535", function() {
}, },
callback); callback);
}, },
], function (error) { ], function (error) {
if (error) if (error)
//console.log("result: %s: error=%s", self.what, error); //console.log("result: %s: error=%s", self.what, error);
assert(!error, self.what); assert(!error, self.what);
done();
done(); });
});
}); });
}); });
// vim:sw=2:sts=2:ts=8:et // vim:sw=2:sts=2:ts=8:et

View File

@@ -1,11 +1,13 @@
var async = require('async'); var async = require('async');
var assert = require('assert-diff')({strict:true}); var assert = require('assert-diff');
var Account = require('ripple-lib').UInt160; var Account = require('ripple-lib').UInt160;
var Remote = require('ripple-lib').Remote; var Remote = require('ripple-lib').Remote;
var Transaction = require('ripple-lib').Transaction; var Transaction = require('ripple-lib').Transaction;
var testutils = require('./testutils'); var testutils = require('./testutils');
var config = testutils.init_config(); var config = testutils.init_config();
assert.options.strict = true;
suite('Order Book', function() { suite('Order Book', function() {
var $ = { }; var $ = { };
@@ -22,15 +24,15 @@ suite('Order Book', function() {
var steps = [ var steps = [
function(callback) { function(callback) {
self.what = 'Create accounts'; self.what = 'Create accounts';
testutils.create_accounts( testutils.create_accounts(
$.remote, $.remote,
'root', 'root',
'20000.0', '20000.0',
[ 'mtgox', 'alice', 'bob' ], [ 'mtgox', 'alice', 'bob' ],
callback callback
); );
}, },
function waitLedgers(callback) { function waitLedgers(callback) {
@@ -49,7 +51,7 @@ suite('Order Book', function() {
testutils.verify_balance( testutils.verify_balance(
$.remote, $.remote,
[ 'mtgox', 'alice', 'bob' ], [ 'mtgox', 'alice', 'bob' ],
'20000000000', '19999999988',
callback callback
); );
}, },
@@ -123,26 +125,27 @@ suite('Order Book', function() {
ob.getOffers(function(err, offers) { ob.getOffers(function(err, offers) {
assert.ifError(err); assert.ifError(err);
// console.log('OFFERS', offers);
//console.log('OFFERS', offers);
var expected = [ var expected = [
{ Account: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn', { Account: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
BookDirectory: 'AE0A97F385FFE42E3096BA3F98A0173090FE66A3C2482FE0570E35FA931A0000', BookDirectory: 'AE0A97F385FFE42E3096BA3F98A0173090FE66A3C2482FE0570E35FA931A0000',
BookNode: '0000000000000000', BookNode: '0000000000000000',
Flags: 0, Flags: 0,
LedgerEntryType: 'Offer', LedgerEntryType: 'Offer',
OwnerNode: '0000000000000000', OwnerNode: '0000000000000000',
Sequence: 2, Sequence: 3,
TakerGets: { currency: 'USD', TakerGets: { currency: 'USD',
issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v', issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v',
value: '10' value: '10'
}, },
TakerPays: '4000', TakerPays: '4000',
index: 'CD6AE78EE0A5438978501A0404D9093597F57B705D566B5070D58BD48F98468C', index: '2A432F386EF28151AF60885CE201CC9331FF494A163D40531A9D253C97E81D61',
owner_funds: '100', owner_funds: '100',
is_fully_funded: true, is_fully_funded: true,
taker_gets_funded: '10', taker_gets_funded: '10',
taker_pays_funded: '4000' } taker_pays_funded: '4000' }
] ]
assert.deepEqual(offers, expected); assert.deepEqual(offers, expected);
@@ -178,19 +181,19 @@ suite('Order Book', function() {
//console.log('OFFERS', offers); //console.log('OFFERS', offers);
var expected = [ var expected = [
{ Account: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn', { Account: 'rG1QQv2nh2gr7RCZ1P8YYcBUKCCN633jCn',
BookDirectory: 'AE0A97F385FFE42E3096BA3F98A0173090FE66A3C2482FE0570E35FA931A0000', BookDirectory: 'AE0A97F385FFE42E3096BA3F98A0173090FE66A3C2482FE0570E35FA931A0000',
BookNode: '0000000000000000', BookNode: '0000000000000000',
Flags: 0, Flags: 0,
LedgerEntryType: 'Offer', LedgerEntryType: 'Offer',
OwnerNode: '0000000000000000', OwnerNode: '0000000000000000',
Sequence: 2, Sequence: 3,
TakerGets: TakerGets:
{ currency: 'USD', { currency: 'USD',
issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v', issuer: 'rGihwhaqU8g7ahwAvTq6iX5rvsfcbgZw6v',
value: '5' }, value: '5' },
TakerPays: '2000', TakerPays: '2000',
index: 'CD6AE78EE0A5438978501A0404D9093597F57B705D566B5070D58BD48F98468C', index: '2A432F386EF28151AF60885CE201CC9331FF494A163D40531A9D253C97E81D61',
owner_funds: '94.5', owner_funds: '94.5',
is_fully_funded: true, is_fully_funded: true,
taker_gets_funded: '5', taker_gets_funded: '5',

View File

@@ -120,7 +120,7 @@ make_suite('Robust transaction submission', function() {
function verifyBalance(callback) { function verifyBalance(callback) {
self.what = 'Verify balance'; self.what = 'Verify balance';
testutils.verify_balance($.remote, 'bob', '20001000000', callback); testutils.verify_balance($.remote, 'bob', '20000999988', callback);
} }
] ]
@@ -205,7 +205,7 @@ make_suite('Robust transaction submission', function() {
function verifyBalance(callback) { function verifyBalance(callback) {
self.what = 'Verify balance'; self.what = 'Verify balance';
testutils.verify_balance($.remote, 'alice', '20001000000', callback); testutils.verify_balance($.remote, 'alice', '20000999988', callback);
} }
] ]
@@ -236,7 +236,7 @@ make_suite('Robust transaction submission', function() {
function verifyBalance(callback) { function verifyBalance(callback) {
self.what = 'Verify balance'; self.what = 'Verify balance';
testutils.verify_balance($.remote, 'alice', '20000000000', callback); testutils.verify_balance($.remote, 'alice', '19999999988', callback);
}, },
function submitTransaction(callback) { function submitTransaction(callback) {
@@ -304,7 +304,7 @@ make_suite('Robust transaction submission', function() {
function verifyBalance(callback) { function verifyBalance(callback) {
self.what = 'Verify balance'; self.what = 'Verify balance';
testutils.verify_balance($.remote, 'alice', '20001000000', callback); testutils.verify_balance($.remote, 'alice', '20000999988', callback);
} }
] ]
@@ -368,7 +368,7 @@ make_suite('Robust transaction submission', function() {
function verifyBalance(callback) { function verifyBalance(callback) {
self.what = 'Verify balance'; self.what = 'Verify balance';
testutils.verify_balance($.remote, 'alice', '20001000000', callback); testutils.verify_balance($.remote, 'alice', '20000999988', callback);
} }
] ]

View File

@@ -269,6 +269,18 @@ function account_dump(remote, account, callback) {
// construct a json result // construct a json result
}; };
function set_account_flag(remote, account, options, callback) {
if (typeof options === 'number') {
options = { set_flag: options };
}
var tx = remote.createTransaction('AccountSet', extend({
account: account
}, options));
submit_transaction(tx, callback);
}
exports.fund_account = exports.fund_account =
fund_account = fund_account =
function(remote, src, account, amount, callback) { function(remote, src, account, amount, callback) {
@@ -282,7 +294,7 @@ function(remote, src, account, amount, callback) {
tx.once('proposed', function (result) { tx.once('proposed', function (result) {
//console.log('proposed: %s', JSON.stringify(result)); //console.log('proposed: %s', JSON.stringify(result));
callback(result.engine_result === 'tesSUCCESS' ? null : new Error()); callback(result.engine_result === 'tesSUCCESS' ? null : result);
}); });
tx.once('error', function (result) { tx.once('error', function (result) {
@@ -295,7 +307,14 @@ function(remote, src, account, amount, callback) {
exports.create_account = exports.create_account =
create_account = create_account =
function(remote, src, account, amount, callback) { function(remote, src, account, amount, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = extend({default_rippling: true}, options);
// Before creating the account, check if it exists in the ledger. // Before creating the account, check if it exists in the ledger.
// If it does, regardless of the balance, fail the test, because // If it does, regardless of the balance, fail the test, because
// the ledger is not in the expected state. // the ledger is not in the expected state.
@@ -307,25 +326,39 @@ function(remote, src, account, amount, callback) {
}); });
info.once('error', function(result) { info.once('error', function(result) {
if (result.error === "remoteError" && result.remote.error === "actNotFound") { var isNotFoundError = result.error === 'remoteError'
// rippled indicated the account does not exist. Create it by funding it. && result.remote.error === 'actNotFound';
fund_account(remote, src, account, amount, callback);
} else { if (!isNotFoundError) {
// Some other error occurred. Pass it up to the callback. return callback(result);
callback(result);
} }
// rippled indicated the account does not exist. Create it by funding it.
fund_account(remote, src, account, amount, function(err) {
if (err) {
callback(err);
} else if (!options.default_rippling) {
callback();
} else {
// Set default rippling on trustlines for account
set_account_flag(remote, account, 8, callback);
}
});
}); });
info.request(); info.request();
} }
function create_accounts(remote, src, amount, accounts, callback) { function create_accounts(remote, src, amount, accounts, options, callback) {
assert.strictEqual(arguments.length, 5); if (typeof options === 'function') {
callback = options;
options = {};
}
remote.set_account_seq(src, 1); remote.set_account_seq(src, 1);
async.forEach(accounts, function (account, callback) { async.forEach(accounts, function (account, callback) {
create_account(remote, src, account, amount, callback); create_account(remote, src, account, amount, options, callback);
}, callback); }, callback);
}; };
@@ -629,6 +662,11 @@ function ledger_wait(remote, tx) {
})(); })();
}; };
function submit_transaction(tx, callback) {
tx.submit(callback);
ledger_wait(tx.remote, tx);
}
exports.account_dump = account_dump; exports.account_dump = account_dump;
exports.build_setup = build_setup; exports.build_setup = build_setup;
exports.build_teardown = build_teardown; exports.build_teardown = build_teardown;
@@ -649,6 +687,7 @@ exports.verify_offer_not_found = verify_offer_not_found;
exports.verify_owner_count = verify_owner_count; exports.verify_owner_count = verify_owner_count;
exports.verify_owner_counts = verify_owner_counts; exports.verify_owner_counts = verify_owner_counts;
exports.ledger_wait = ledger_wait; exports.ledger_wait = ledger_wait;
exports.submit_transaction = submit_transaction;
// Close up all unclosed servers on exit. // Close up all unclosed servers on exit.
process.on('exit', function() { process.on('exit', function() {