@lodestar/state-transition 1.41.0-dev.0df187678b → 1.41.0-dev.165a02f873
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/block/processExecutionPayloadEnvelope.d.ts +4 -1
- package/lib/block/processExecutionPayloadEnvelope.d.ts.map +1 -1
- package/lib/block/processExecutionPayloadEnvelope.js +20 -14
- package/lib/block/processExecutionPayloadEnvelope.js.map +1 -1
- package/package.json +7 -7
- package/src/block/processExecutionPayloadEnvelope.ts +29 -15
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { gloas } from "@lodestar/types";
|
|
2
2
|
import { CachedBeaconStateGloas } from "../types.ts";
|
|
3
|
-
export
|
|
3
|
+
export type ProcessExecutionPayloadEnvelopeOpts = {
|
|
4
|
+
dontTransferCache?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function processExecutionPayloadEnvelope(state: CachedBeaconStateGloas, signedEnvelope: gloas.SignedExecutionPayloadEnvelope, verify: boolean, opts?: ProcessExecutionPayloadEnvelopeOpts): CachedBeaconStateGloas;
|
|
4
7
|
//# sourceMappingURL=processExecutionPayloadEnvelope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processExecutionPayloadEnvelope.d.ts","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,KAAK,EAAM,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"processExecutionPayloadEnvelope.d.ts","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,KAAK,EAAM,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAC,sBAAsB,EAAC,MAAM,aAAa,CAAC;AAMnD,MAAM,MAAM,mCAAmC,GAAG;IAChD,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAKF,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,sBAAsB,EAC7B,cAAc,EAAE,KAAK,CAAC,8BAA8B,EACpD,MAAM,EAAE,OAAO,EACf,IAAI,CAAC,EAAE,mCAAmC,GACzC,sBAAsB,CAoDxB"}
|
|
@@ -6,39 +6,45 @@ import { computeSigningRoot, computeTimeAtSlot } from "../util/index.js";
|
|
|
6
6
|
import { processConsolidationRequest } from "./processConsolidationRequest.js";
|
|
7
7
|
import { processDepositRequest } from "./processDepositRequest.js";
|
|
8
8
|
import { processWithdrawalRequest } from "./processWithdrawalRequest.js";
|
|
9
|
-
//
|
|
10
|
-
|
|
9
|
+
// Unlike other block processing functions which mutate state in-place, this function
|
|
10
|
+
// clones the state and returns the post-state, similar to stateTransition().
|
|
11
|
+
// This function does not call execution engine to verify payload. Need to call it from other place.
|
|
12
|
+
export function processExecutionPayloadEnvelope(state, signedEnvelope, verify, opts) {
|
|
11
13
|
const envelope = signedEnvelope.message;
|
|
12
14
|
const payload = envelope.payload;
|
|
13
15
|
const fork = state.config.getForkSeq(envelope.slot);
|
|
14
16
|
if (verify && !verifyExecutionPayloadEnvelopeSignature(state, signedEnvelope)) {
|
|
15
17
|
throw Error(`Execution payload envelope has invalid signature builderIndex=${envelope.builderIndex}`);
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
// .clone() before mutating state, similar to stateTransition()
|
|
20
|
+
const postState = state.clone(opts?.dontTransferCache);
|
|
21
|
+
validateExecutionPayloadEnvelope(postState, envelope);
|
|
18
22
|
const requests = envelope.executionRequests;
|
|
19
23
|
for (const deposit of requests.deposits) {
|
|
20
|
-
processDepositRequest(fork,
|
|
24
|
+
processDepositRequest(fork, postState, deposit);
|
|
21
25
|
}
|
|
22
26
|
for (const withdrawal of requests.withdrawals) {
|
|
23
|
-
processWithdrawalRequest(fork,
|
|
27
|
+
processWithdrawalRequest(fork, postState, withdrawal);
|
|
24
28
|
}
|
|
25
29
|
for (const consolidation of requests.consolidations) {
|
|
26
|
-
processConsolidationRequest(
|
|
30
|
+
processConsolidationRequest(postState, consolidation);
|
|
27
31
|
}
|
|
28
32
|
// Queue the builder payment
|
|
29
|
-
const paymentIndex = SLOTS_PER_EPOCH + (
|
|
30
|
-
const payment =
|
|
33
|
+
const paymentIndex = SLOTS_PER_EPOCH + (postState.slot % SLOTS_PER_EPOCH);
|
|
34
|
+
const payment = postState.builderPendingPayments.get(paymentIndex).clone();
|
|
31
35
|
const amount = payment.withdrawal.amount;
|
|
32
36
|
if (amount > 0) {
|
|
33
|
-
|
|
37
|
+
postState.builderPendingWithdrawals.push(payment.withdrawal);
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
postState.builderPendingPayments.set(paymentIndex, ssz.gloas.BuilderPendingPayment.defaultViewDU());
|
|
36
40
|
// Cache the execution payload hash
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
postState.executionPayloadAvailability.set(postState.slot % SLOTS_PER_HISTORICAL_ROOT, true);
|
|
42
|
+
postState.latestBlockHash = payload.blockHash;
|
|
43
|
+
postState.commit();
|
|
44
|
+
if (verify && !byteArrayEquals(envelope.stateRoot, postState.hashTreeRoot())) {
|
|
45
|
+
throw new Error(`Envelope's state root does not match state envelope=${toRootHex(envelope.stateRoot)} state=${toRootHex(postState.hashTreeRoot())}`);
|
|
41
46
|
}
|
|
47
|
+
return postState;
|
|
42
48
|
}
|
|
43
49
|
function validateExecutionPayloadEnvelope(state, envelope) {
|
|
44
50
|
const payload = envelope.payload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processExecutionPayloadEnvelope.js","sourceRoot":"","sources":["../../src/block/processExecutionPayloadEnvelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,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AC,GAAG,CAAC,KAAK,CAAC,wBAAwB,EAAE,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAE3G,IAAI,CAAC;QACH,IAAI,SAAoB,CAAC;QAEzB,IAAI,YAAY,KAAK,wBAAwB,EAAE,CAAC;YAC9C,MAAM,cAAc,GAAG,KAAK,CAAC,iBAAiB,CAAC,aAAa,CAAC;YAC7D,MAAM,cAAc,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACtE,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,OAAO,KAAK,CAAC;YACf,CAAC;YACD,SAAS,GAAG,cAAc,CAAC;QAC7B,CAAC;aAAM,CAAC;YACN,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;QACnF,CAAC;QACD,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAEtE,OAAO,MAAM,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,KAAK,CAAC,CAAC,8FAA8F;IAC9G,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.41.0-dev.
|
|
14
|
+
"version": "1.41.0-dev.165a02f873",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"@chainsafe/pubkey-index-map": "^3.0.0",
|
|
63
63
|
"@chainsafe/ssz": "^1.2.2",
|
|
64
64
|
"@chainsafe/swap-or-not-shuffle": "^1.2.1",
|
|
65
|
-
"@lodestar/config": "^1.41.0-dev.
|
|
66
|
-
"@lodestar/params": "^1.41.0-dev.
|
|
67
|
-
"@lodestar/types": "^1.41.0-dev.
|
|
68
|
-
"@lodestar/utils": "^1.41.0-dev.
|
|
65
|
+
"@lodestar/config": "^1.41.0-dev.165a02f873",
|
|
66
|
+
"@lodestar/params": "^1.41.0-dev.165a02f873",
|
|
67
|
+
"@lodestar/types": "^1.41.0-dev.165a02f873",
|
|
68
|
+
"@lodestar/utils": "^1.41.0-dev.165a02f873",
|
|
69
69
|
"@vekexasia/bigint-buffer2": "^1.1.0"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@lodestar/api": "^1.41.0-dev.
|
|
72
|
+
"@lodestar/api": "^1.41.0-dev.165a02f873"
|
|
73
73
|
},
|
|
74
74
|
"keywords": [
|
|
75
75
|
"ethereum",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"beacon",
|
|
78
78
|
"blockchain"
|
|
79
79
|
],
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "08a97ee173fe65d3c757a279a740741ca8bf1502"
|
|
81
81
|
}
|
|
@@ -13,12 +13,19 @@ import {processConsolidationRequest} from "./processConsolidationRequest.ts";
|
|
|
13
13
|
import {processDepositRequest} from "./processDepositRequest.ts";
|
|
14
14
|
import {processWithdrawalRequest} from "./processWithdrawalRequest.ts";
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
export type ProcessExecutionPayloadEnvelopeOpts = {
|
|
17
|
+
dontTransferCache?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Unlike other block processing functions which mutate state in-place, this function
|
|
21
|
+
// clones the state and returns the post-state, similar to stateTransition().
|
|
22
|
+
// This function does not call execution engine to verify payload. Need to call it from other place.
|
|
17
23
|
export function processExecutionPayloadEnvelope(
|
|
18
24
|
state: CachedBeaconStateGloas,
|
|
19
25
|
signedEnvelope: gloas.SignedExecutionPayloadEnvelope,
|
|
20
|
-
verify: boolean
|
|
21
|
-
|
|
26
|
+
verify: boolean,
|
|
27
|
+
opts?: ProcessExecutionPayloadEnvelopeOpts
|
|
28
|
+
): CachedBeaconStateGloas {
|
|
22
29
|
const envelope = signedEnvelope.message;
|
|
23
30
|
const payload = envelope.payload;
|
|
24
31
|
const fork = state.config.getForkSeq(envelope.slot);
|
|
@@ -27,42 +34,49 @@ export function processExecutionPayloadEnvelope(
|
|
|
27
34
|
throw Error(`Execution payload envelope has invalid signature builderIndex=${envelope.builderIndex}`);
|
|
28
35
|
}
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
// .clone() before mutating state, similar to stateTransition()
|
|
38
|
+
const postState = state.clone(opts?.dontTransferCache) as CachedBeaconStateGloas;
|
|
39
|
+
|
|
40
|
+
validateExecutionPayloadEnvelope(postState, envelope);
|
|
31
41
|
|
|
32
42
|
const requests = envelope.executionRequests;
|
|
33
43
|
|
|
34
44
|
for (const deposit of requests.deposits) {
|
|
35
|
-
processDepositRequest(fork,
|
|
45
|
+
processDepositRequest(fork, postState, deposit);
|
|
36
46
|
}
|
|
37
47
|
|
|
38
48
|
for (const withdrawal of requests.withdrawals) {
|
|
39
|
-
processWithdrawalRequest(fork,
|
|
49
|
+
processWithdrawalRequest(fork, postState, withdrawal);
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
for (const consolidation of requests.consolidations) {
|
|
43
|
-
processConsolidationRequest(
|
|
53
|
+
processConsolidationRequest(postState, consolidation);
|
|
44
54
|
}
|
|
45
55
|
|
|
46
56
|
// Queue the builder payment
|
|
47
|
-
const paymentIndex = SLOTS_PER_EPOCH + (
|
|
48
|
-
const payment =
|
|
57
|
+
const paymentIndex = SLOTS_PER_EPOCH + (postState.slot % SLOTS_PER_EPOCH);
|
|
58
|
+
const payment = postState.builderPendingPayments.get(paymentIndex).clone();
|
|
49
59
|
const amount = payment.withdrawal.amount;
|
|
50
60
|
|
|
51
61
|
if (amount > 0) {
|
|
52
|
-
|
|
62
|
+
postState.builderPendingWithdrawals.push(payment.withdrawal);
|
|
53
63
|
}
|
|
54
64
|
|
|
55
|
-
|
|
65
|
+
postState.builderPendingPayments.set(paymentIndex, ssz.gloas.BuilderPendingPayment.defaultViewDU());
|
|
56
66
|
|
|
57
67
|
// Cache the execution payload hash
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
postState.executionPayloadAvailability.set(postState.slot % SLOTS_PER_HISTORICAL_ROOT, true);
|
|
69
|
+
postState.latestBlockHash = payload.blockHash;
|
|
60
70
|
|
|
61
|
-
|
|
71
|
+
postState.commit();
|
|
72
|
+
|
|
73
|
+
if (verify && !byteArrayEquals(envelope.stateRoot, postState.hashTreeRoot())) {
|
|
62
74
|
throw new Error(
|
|
63
|
-
`Envelope's state root does not match state envelope=${toRootHex(envelope.stateRoot)} state=${toRootHex(
|
|
75
|
+
`Envelope's state root does not match state envelope=${toRootHex(envelope.stateRoot)} state=${toRootHex(postState.hashTreeRoot())}`
|
|
64
76
|
);
|
|
65
77
|
}
|
|
78
|
+
|
|
79
|
+
return postState;
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
function validateExecutionPayloadEnvelope(
|