Skip to content

Commit 41714b4

Browse files
committed
Merge branch 'master' into release/1.16
2 parents d818a9a + b964b65 commit 41714b4

File tree

211 files changed

+7940
-1815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+7940
-1815
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ jobs:
5555
cache: false
5656

5757
- name: Run tests
58-
run: go test ./...
58+
run: go run build/ci.go test

.github/workflows/validate_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
with:
1414
script: |
1515
const prTitle = context.payload.pull_request.title;
16-
const titleRegex = /^(\.?[\w\s,{}/]+): .+/;
16+
const titleRegex = /^([\w\s,{}/.]+): .+/;
1717
1818
if (!titleRegex.test(prTitle)) {
1919
core.setFailed(`PR title "${prTitle}" does not match required format: directory, ...: description`);

accounts/abi/bind/v2/base.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ func NewBoundContract(address common.Address, abi abi.ABI, caller ContractCaller
150150
}
151151
}
152152

153+
// Address returns the deployment address of the contract.
154+
func (c *BoundContract) Address() common.Address {
155+
return c.address
156+
}
157+
153158
// Call invokes the (constant) contract method with params as input values and
154159
// sets the output to result. The result type might be a single field for simple
155160
// returns, a slice of interfaces for anonymous returns and a struct for named

accounts/abi/bind/v2/util_test.go

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,29 @@ func TestWaitDeployed(t *testing.T) {
100100
}
101101

102102
func TestWaitDeployedCornerCases(t *testing.T) {
103-
backend := simulated.NewBackend(
104-
types.GenesisAlloc{
105-
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
106-
},
103+
var (
104+
backend = simulated.NewBackend(
105+
types.GenesisAlloc{
106+
crypto.PubkeyToAddress(testKey.PublicKey): {Balance: big.NewInt(10000000000000000)},
107+
},
108+
)
109+
head, _ = backend.Client().HeaderByNumber(t.Context(), nil) // Should be child's, good enough
110+
gasPrice = new(big.Int).Add(head.BaseFee, big.NewInt(1))
111+
signer = types.LatestSigner(params.AllDevChainProtocolChanges)
112+
code = common.FromHex("6060604052600a8060106000396000f360606040526008565b00")
113+
ctx, cancel = context.WithCancel(t.Context())
107114
)
108115
defer backend.Close()
109116

110-
head, _ := backend.Client().HeaderByNumber(context.Background(), nil) // Should be child's, good enough
111-
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
112-
113-
// Create a transaction to an account.
114-
code := "6060604052600a8060106000396000f360606040526008565b00"
115-
tx := types.NewTransaction(0, common.HexToAddress("0x01"), big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
116-
tx, _ = types.SignTx(tx, types.LatestSigner(params.AllDevChainProtocolChanges), testKey)
117-
ctx, cancel := context.WithCancel(context.Background())
118-
defer cancel()
117+
// 1. WaitDeploy on a transaction that does not deploy a contract, verify it
118+
// returns an error.
119+
tx := types.MustSignNewTx(testKey, signer, &types.LegacyTx{
120+
Nonce: 0,
121+
To: &common.Address{0x01},
122+
Gas: 300000,
123+
GasPrice: gasPrice,
124+
Data: code,
125+
})
119126
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
120127
t.Errorf("failed to send transaction: %q", err)
121128
}
@@ -124,19 +131,35 @@ func TestWaitDeployedCornerCases(t *testing.T) {
124131
t.Errorf("error mismatch: want %q, got %q, ", bind.ErrNoAddressInReceipt, err)
125132
}
126133

127-
// Create a transaction that is not mined.
128-
tx = types.NewContractCreation(1, big.NewInt(0), 3000000, gasPrice, common.FromHex(code))
129-
tx, _ = types.SignTx(tx, types.LatestSigner(params.AllDevChainProtocolChanges), testKey)
130-
134+
// 2. Create a contract, but cancel the WaitDeploy before it is mined.
135+
tx = types.MustSignNewTx(testKey, signer, &types.LegacyTx{
136+
Nonce: 1,
137+
Gas: 300000,
138+
GasPrice: gasPrice,
139+
Data: code,
140+
})
141+
142+
// Wait in another thread so that we can quickly cancel it after submitting
143+
// the transaction.
144+
done := make(chan struct{})
131145
go func() {
132-
contextCanceled := errors.New("context canceled")
133-
if _, err := bind.WaitDeployed(ctx, backend.Client(), tx.Hash()); err.Error() != contextCanceled.Error() {
134-
t.Errorf("error mismatch: want %q, got %q, ", contextCanceled, err)
146+
defer close(done)
147+
want := errors.New("context canceled")
148+
_, err := bind.WaitDeployed(ctx, backend.Client(), tx.Hash())
149+
if err == nil || errors.Is(want, err) {
150+
t.Errorf("error mismatch: want %v, got %v", want, err)
135151
}
136152
}()
137153

138154
if err := backend.Client().SendTransaction(ctx, tx); err != nil {
139155
t.Errorf("failed to send transaction: %q", err)
140156
}
141157
cancel()
158+
159+
// Wait for goroutine to exit or for a timeout.
160+
select {
161+
case <-done:
162+
case <-time.After(time.Second * 2):
163+
t.Fatalf("failed to cancel wait deploy")
164+
}
142165
}

accounts/keystore/keystore.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ func (ks *KeyStore) init(keydir string) {
9999
// TODO: In order for this finalizer to work, there must be no references
100100
// to ks. addressCache doesn't keep a reference but unlocked keys do,
101101
// so the finalizer will not trigger until all timed unlocks have expired.
102-
runtime.SetFinalizer(ks, func(m *KeyStore) {
103-
m.cache.close()
104-
})
102+
runtime.AddCleanup(ks, func(c *accountCache) {
103+
c.close()
104+
}, ks.cache)
105+
105106
// Create the initial list of wallets from the cache
106107
accs := ks.cache.accounts()
107108
ks.wallets = make([]accounts.Wallet, len(accs))
@@ -195,11 +196,14 @@ func (ks *KeyStore) Subscribe(sink chan<- accounts.WalletEvent) event.Subscripti
195196
// forces a manual refresh (only triggers for systems where the filesystem notifier
196197
// is not running).
197198
func (ks *KeyStore) updater() {
199+
ticker := time.NewTicker(walletRefreshCycle)
200+
defer ticker.Stop()
201+
198202
for {
199203
// Wait for an account update or a refresh timeout
200204
select {
201205
case <-ks.changes:
202-
case <-time.After(walletRefreshCycle):
206+
case <-ticker.C:
203207
}
204208
// Run the wallet refresher
205209
ks.refreshWallets()

beacon/blsync/block_sync_test.go

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var (
3232
testServer2 = testServer("testServer2")
3333

3434
testBlock1 = types.NewBeaconBlock(&deneb.BeaconBlock{
35-
Slot: 123,
35+
Slot: 127,
3636
Body: deneb.BeaconBlockBody{
3737
ExecutionPayload: deneb.ExecutionPayload{
3838
BlockNumber: 456,
@@ -41,14 +41,22 @@ var (
4141
},
4242
})
4343
testBlock2 = types.NewBeaconBlock(&deneb.BeaconBlock{
44-
Slot: 124,
44+
Slot: 128,
4545
Body: deneb.BeaconBlockBody{
4646
ExecutionPayload: deneb.ExecutionPayload{
4747
BlockNumber: 457,
4848
BlockHash: zrntcommon.Hash32(common.HexToHash("011703f39c664efc1c6cf5f49ca09b595581eec572d4dfddd3d6179a9e63e655")),
4949
},
5050
},
5151
})
52+
testFinal1 = types.NewExecutionHeader(&deneb.ExecutionPayloadHeader{
53+
BlockNumber: 395,
54+
BlockHash: zrntcommon.Hash32(common.HexToHash("abbe7625624bf8ddd84723709e2758956289465dd23475f02387e0854942666")),
55+
})
56+
testFinal2 = types.NewExecutionHeader(&deneb.ExecutionPayloadHeader{
57+
BlockNumber: 420,
58+
BlockHash: zrntcommon.Hash32(common.HexToHash("9182a6ef8723654de174283750932ccc092378549836bf4873657eeec474598")),
59+
})
5260
)
5361

5462
type testServer string
@@ -66,29 +74,37 @@ func TestBlockSync(t *testing.T) {
6674
ts.AddServer(testServer1, 1)
6775
ts.AddServer(testServer2, 1)
6876

69-
expHeadBlock := func(expHead *types.BeaconBlock) {
77+
expHeadEvent := func(expHead *types.BeaconBlock, expFinal *types.ExecutionHeader) {
7078
t.Helper()
7179
var expNumber, headNumber uint64
80+
var expFinalHash, finalHash common.Hash
7281
if expHead != nil {
7382
p, err := expHead.ExecutionPayload()
7483
if err != nil {
7584
t.Fatalf("expHead.ExecutionPayload() failed: %v", err)
7685
}
7786
expNumber = p.NumberU64()
7887
}
88+
if expFinal != nil {
89+
expFinalHash = expFinal.BlockHash()
90+
}
7991
select {
8092
case event := <-headCh:
8193
headNumber = event.Block.NumberU64()
94+
finalHash = event.Finalized
8295
default:
8396
}
8497
if headNumber != expNumber {
8598
t.Errorf("Wrong head block, expected block number %d, got %d)", expNumber, headNumber)
8699
}
100+
if finalHash != expFinalHash {
101+
t.Errorf("Wrong finalized block, expected block hash %064x, got %064x)", expFinalHash[:], finalHash[:])
102+
}
87103
}
88104

89105
// no block requests expected until head tracker knows about a head
90106
ts.Run(1)
91-
expHeadBlock(nil)
107+
expHeadEvent(nil, nil)
92108

93109
// set block 1 as prefetch head, announced by server 2
94110
head1 := blockHeadInfo(testBlock1)
@@ -103,12 +119,13 @@ func TestBlockSync(t *testing.T) {
103119
ts.AddAllowance(testServer2, 1)
104120
ts.Run(3)
105121
// head block still not expected as the fetched block is not the validated head yet
106-
expHeadBlock(nil)
122+
expHeadEvent(nil, nil)
107123

108124
// set as validated head, expect no further requests but block 1 set as head block
109125
ht.validated.Header = testBlock1.Header()
126+
ht.finalized, ht.finalizedPayload = testBlock1.Header(), testFinal1
110127
ts.Run(4)
111-
expHeadBlock(testBlock1)
128+
expHeadEvent(testBlock1, testFinal1)
112129

113130
// set block 2 as prefetch head, announced by server 1
114131
head2 := blockHeadInfo(testBlock2)
@@ -126,17 +143,26 @@ func TestBlockSync(t *testing.T) {
126143
// expect req2 retry to server 2
127144
ts.Run(7, testServer2, sync.ReqBeaconBlock(head2.BlockRoot))
128145
// now head block should be unavailable again
129-
expHeadBlock(nil)
146+
expHeadEvent(nil, nil)
130147

131148
// valid response, now head block should be block 2 immediately as it is already validated
149+
// but head event is still not expected because an epoch boundary was crossed and the
150+
// expected finality update has not arrived yet
132151
ts.RequestEvent(request.EvResponse, ts.Request(7, 1), testBlock2)
133152
ts.Run(8)
134-
expHeadBlock(testBlock2)
153+
expHeadEvent(nil, nil)
154+
155+
// expected finality update arrived, now a head event is expected
156+
ht.finalized, ht.finalizedPayload = testBlock2.Header(), testFinal2
157+
ts.Run(9)
158+
expHeadEvent(testBlock2, testFinal2)
135159
}
136160

137161
type testHeadTracker struct {
138-
prefetch types.HeadInfo
139-
validated types.SignedHeader
162+
prefetch types.HeadInfo
163+
validated types.SignedHeader
164+
finalized types.Header
165+
finalizedPayload *types.ExecutionHeader
140166
}
141167

142168
func (h *testHeadTracker) PrefetchHead() types.HeadInfo {
@@ -151,13 +177,14 @@ func (h *testHeadTracker) ValidatedOptimistic() (types.OptimisticUpdate, bool) {
151177
}, h.validated.Header != (types.Header{})
152178
}
153179

154-
// TODO add test case for finality
155180
func (h *testHeadTracker) ValidatedFinality() (types.FinalityUpdate, bool) {
156-
finalized := types.NewExecutionHeader(new(deneb.ExecutionPayloadHeader))
181+
if h.validated.Header == (types.Header{}) || h.finalizedPayload == nil {
182+
return types.FinalityUpdate{}, false
183+
}
157184
return types.FinalityUpdate{
158-
Attested: types.HeaderWithExecProof{Header: h.validated.Header},
159-
Finalized: types.HeaderWithExecProof{PayloadHeader: finalized},
185+
Attested: types.HeaderWithExecProof{Header: h.finalized},
186+
Finalized: types.HeaderWithExecProof{Header: h.finalized, PayloadHeader: h.finalizedPayload},
160187
Signature: h.validated.Signature,
161188
SignatureSlot: h.validated.SignatureSlot,
162-
}, h.validated.Header != (types.Header{})
189+
}, true
163190
}

beacon/engine/gen_epe.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon/engine/types.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,22 @@ import (
3333
type PayloadVersion byte
3434

3535
var (
36+
// PayloadV1 is the identifier of ExecutionPayloadV1 introduced in paris fork.
37+
// https://github.com/ethereum/execution-apis/blob/main/src/engine/paris.md#executionpayloadv1
3638
PayloadV1 PayloadVersion = 0x1
39+
40+
// PayloadV2 is the identifier of ExecutionPayloadV2 introduced in shanghai fork.
41+
//
42+
// https://github.com/ethereum/execution-apis/blob/main/src/engine/shanghai.md#executionpayloadv2
43+
// ExecutionPayloadV2 has the syntax of ExecutionPayloadV1 and appends a
44+
// single field: withdrawals.
3745
PayloadV2 PayloadVersion = 0x2
46+
47+
// PayloadV3 is the identifier of ExecutionPayloadV3 introduced in cancun fork.
48+
//
49+
// https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#executionpayloadv3
50+
// ExecutionPayloadV3 has the syntax of ExecutionPayloadV2 and appends the new
51+
// fields: blobGasUsed and excessBlobGas.
3852
PayloadV3 PayloadVersion = 0x3
3953
)
4054

@@ -106,13 +120,18 @@ type StatelessPayloadStatusV1 struct {
106120
type ExecutionPayloadEnvelope struct {
107121
ExecutionPayload *ExecutableData `json:"executionPayload" gencodec:"required"`
108122
BlockValue *big.Int `json:"blockValue" gencodec:"required"`
109-
BlobsBundle *BlobsBundleV1 `json:"blobsBundle"`
123+
BlobsBundle *BlobsBundle `json:"blobsBundle"`
110124
Requests [][]byte `json:"executionRequests"`
111125
Override bool `json:"shouldOverrideBuilder"`
112126
Witness *hexutil.Bytes `json:"witness,omitempty"`
113127
}
114128

115-
type BlobsBundleV1 struct {
129+
// BlobsBundle includes the marshalled sidecar data. Note this structure is
130+
// shared by BlobsBundleV1 and BlobsBundleV2 for the sake of simplicity.
131+
//
132+
// - BlobsBundleV1: proofs contain exactly len(blobs) kzg proofs.
133+
// - BlobsBundleV2: proofs contain exactly CELLS_PER_EXT_BLOB * len(blobs) cell proofs.
134+
type BlobsBundle struct {
116135
Commitments []hexutil.Bytes `json:"commitments"`
117136
Proofs []hexutil.Bytes `json:"proofs"`
118137
Blobs []hexutil.Bytes `json:"blobs"`
@@ -125,7 +144,7 @@ type BlobAndProofV1 struct {
125144

126145
type BlobAndProofV2 struct {
127146
Blob hexutil.Bytes `json:"blob"`
128-
CellProofs []hexutil.Bytes `json:"proofs"`
147+
CellProofs []hexutil.Bytes `json:"proofs"` // proofs MUST contain exactly CELLS_PER_EXT_BLOB cell proofs.
129148
}
130149

131150
// JSON type overrides for ExecutionPayloadEnvelope.
@@ -327,18 +346,27 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types.
327346
}
328347

329348
// Add blobs.
330-
bundle := BlobsBundleV1{
349+
bundle := BlobsBundle{
331350
Commitments: make([]hexutil.Bytes, 0),
332351
Blobs: make([]hexutil.Bytes, 0),
333352
Proofs: make([]hexutil.Bytes, 0),
334353
}
335354
for _, sidecar := range sidecars {
336355
for j := range sidecar.Blobs {
337-
bundle.Blobs = append(bundle.Blobs, hexutil.Bytes(sidecar.Blobs[j][:]))
338-
bundle.Commitments = append(bundle.Commitments, hexutil.Bytes(sidecar.Commitments[j][:]))
356+
bundle.Blobs = append(bundle.Blobs, sidecar.Blobs[j][:])
357+
bundle.Commitments = append(bundle.Commitments, sidecar.Commitments[j][:])
339358
}
359+
// - Before the Osaka fork, only version-0 blob transactions should be packed,
360+
// with the proof length equal to len(blobs).
361+
//
362+
// - After the Osaka fork, only version-1 blob transactions should be packed,
363+
// with the proof length equal to CELLS_PER_EXT_BLOB * len(blobs).
364+
//
365+
// Ideally, length validation should be performed based on the bundle version.
366+
// In practice, this is unnecessary because blob transaction filtering is
367+
// already done during payload construction.
340368
for _, proof := range sidecar.Proofs {
341-
bundle.Proofs = append(bundle.Proofs, hexutil.Bytes(proof[:]))
369+
bundle.Proofs = append(bundle.Proofs, proof[:])
342370
}
343371
}
344372

0 commit comments

Comments
 (0)