@ocap/tx-protocols 1.18.139 → 1.18.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/execute.js +2 -0
- package/lib/protocols/rollup/claim-reward.js +10 -4
- package/lib/util.js +21 -2
- package/package.json +14 -14
package/lib/execute.js
CHANGED
|
@@ -149,6 +149,8 @@ module.exports = ({ filter, runAsLambda }) => {
|
|
|
149
149
|
flushEvents(newCtx, { txState });
|
|
150
150
|
});
|
|
151
151
|
} catch (err) {
|
|
152
|
+
const txState = context.states.tx.create(ctx, error ? error.code || 'INTERNAL' : 'OK', false);
|
|
153
|
+
logError('failed to save invalid transaction to statedb', JSON.stringify(txState, null));
|
|
152
154
|
logError('failed to save invalid transaction to statedb', err);
|
|
153
155
|
}
|
|
154
156
|
}
|
|
@@ -149,11 +149,17 @@ runner.use(async (context, next) => {
|
|
|
149
149
|
changes.account.push({ address: blockState.proposer, delta: proposer.toString(10), action: 'fee' });
|
|
150
150
|
|
|
151
151
|
// block signers share the validator part
|
|
152
|
-
// FIXME: delegation is not supported here yet
|
|
153
152
|
const validators = blockState.signatures.map((s) => s.signer);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
const validatorShares = splitTxFee({
|
|
154
|
+
total: validator,
|
|
155
|
+
shares: validators.reduce((acc, signer) => {
|
|
156
|
+
acc[signer] = 1;
|
|
157
|
+
return acc;
|
|
158
|
+
}, {}),
|
|
159
|
+
rateBase: new BN(validators.length),
|
|
160
|
+
});
|
|
161
|
+
Object.keys(validatorShares).forEach((v) =>
|
|
162
|
+
changes.account.push({ address: v, delta: validatorShares[v], action: 'fee' })
|
|
157
163
|
);
|
|
158
164
|
}
|
|
159
165
|
});
|
package/lib/util.js
CHANGED
|
@@ -176,7 +176,7 @@ const getDelegationRequirements = (context) => {
|
|
|
176
176
|
];
|
|
177
177
|
};
|
|
178
178
|
|
|
179
|
-
const splitTxFee = ({ total, shares = {}, stringify = true }) => {
|
|
179
|
+
const splitTxFee = ({ total, shares = {}, stringify = true, rateBase = RATE_BASE }) => {
|
|
180
180
|
const totalAmount = new BN(total);
|
|
181
181
|
if (totalAmount.isNeg()) {
|
|
182
182
|
throw new Error('NEGATIVE_TOTAL_AMOUNT', 'Unexpected negative total when splitTxFee, abort!');
|
|
@@ -186,12 +186,31 @@ const splitTxFee = ({ total, shares = {}, stringify = true }) => {
|
|
|
186
186
|
throw new Error('NEGATIVE_FEE_SHARE', `Unexpected negative shares[${key}] when splitTxFee, abort!`);
|
|
187
187
|
}
|
|
188
188
|
});
|
|
189
|
+
if (
|
|
190
|
+
Object.values(shares)
|
|
191
|
+
.reduce((sum, x) => sum.add(new BN(x)), new BN(0))
|
|
192
|
+
.eq(rateBase) === false
|
|
193
|
+
) {
|
|
194
|
+
throw new Error('INVALID_FEE_SHARE', 'Invalid share config when splitTxFee, abort!');
|
|
195
|
+
}
|
|
189
196
|
|
|
190
197
|
const rewardShares = Object.keys(shares).reduce((acc, x) => {
|
|
191
|
-
acc[x] = totalAmount.mul(new BN(shares[x])).div(
|
|
198
|
+
acc[x] = totalAmount.mul(new BN(shares[x])).div(rateBase);
|
|
192
199
|
return acc;
|
|
193
200
|
}, {});
|
|
194
201
|
|
|
202
|
+
// ensure sum of shares equals to total, to avoid floating point precision issue
|
|
203
|
+
// Adjust the first share to compensate for rounding errors
|
|
204
|
+
if (
|
|
205
|
+
Object.values(rewardShares)
|
|
206
|
+
.reduce((sum, x) => sum.add(x), new BN(0))
|
|
207
|
+
.eq(totalAmount) === false
|
|
208
|
+
) {
|
|
209
|
+
const firstKey = Object.keys(rewardShares)[0];
|
|
210
|
+
const currentSum = Object.values(rewardShares).reduce((sum, x) => sum.add(x), new BN(0));
|
|
211
|
+
rewardShares[firstKey] = rewardShares[firstKey].add(totalAmount.sub(currentSum));
|
|
212
|
+
}
|
|
213
|
+
|
|
195
214
|
return Object.keys(rewardShares).reduce((acc, x) => {
|
|
196
215
|
acc[x] = stringify ? rewardShares[x].toString(10) : rewardShares[x];
|
|
197
216
|
return acc;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.18.
|
|
6
|
+
"version": "1.18.142",
|
|
7
7
|
"description": "Predefined tx pipeline sets to execute certain type of transactions",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -21,18 +21,18 @@
|
|
|
21
21
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@arcblock/did": "1.18.
|
|
25
|
-
"@arcblock/did-util": "1.18.
|
|
26
|
-
"@arcblock/jwt": "1.18.
|
|
27
|
-
"@arcblock/validator": "1.18.
|
|
28
|
-
"@ocap/asset": "1.18.
|
|
29
|
-
"@ocap/mcrypto": "1.18.
|
|
30
|
-
"@ocap/merkle-tree": "1.18.
|
|
31
|
-
"@ocap/message": "1.18.
|
|
32
|
-
"@ocap/state": "1.18.
|
|
33
|
-
"@ocap/tx-pipeline": "1.18.
|
|
34
|
-
"@ocap/util": "1.18.
|
|
35
|
-
"@ocap/wallet": "1.18.
|
|
24
|
+
"@arcblock/did": "1.18.142",
|
|
25
|
+
"@arcblock/did-util": "1.18.142",
|
|
26
|
+
"@arcblock/jwt": "1.18.142",
|
|
27
|
+
"@arcblock/validator": "1.18.142",
|
|
28
|
+
"@ocap/asset": "1.18.142",
|
|
29
|
+
"@ocap/mcrypto": "1.18.142",
|
|
30
|
+
"@ocap/merkle-tree": "1.18.142",
|
|
31
|
+
"@ocap/message": "1.18.142",
|
|
32
|
+
"@ocap/state": "1.18.142",
|
|
33
|
+
"@ocap/tx-pipeline": "1.18.142",
|
|
34
|
+
"@ocap/util": "1.18.142",
|
|
35
|
+
"@ocap/wallet": "1.18.142",
|
|
36
36
|
"debug": "^4.3.6",
|
|
37
37
|
"deep-diff": "^1.0.2",
|
|
38
38
|
"empty-value": "^1.0.1",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"jest": "^29.7.0",
|
|
48
48
|
"start-server-and-test": "^1.14.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "fa18a9eddbb0cad69398c69c7930018593f4fb31"
|
|
51
51
|
}
|