Skip to content

Commit c548363

Browse files
Merge branch 'master' into illia-malachyn/6617-new-ws-handler
2 parents b42d8a7 + a4b5132 commit c548363

File tree

5 files changed

+185
-4
lines changed

5 files changed

+185
-4
lines changed

.github/workflows/ci.yml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,19 @@ jobs:
5555
# https://github.com/golangci/golangci-lint-action/issues/244
5656
skip-cache: true
5757

58-
5958
tidy:
6059
name: Tidy
6160
runs-on: ubuntu-latest
6261
steps:
6362
- name: Checkout repo
6463
uses: actions/checkout@v3
64+
65+
- name: Setup private build environment
66+
if: ${{ vars.PRIVATE_BUILDS_SUPPORTED == 'true' }}
67+
uses: ./actions/private-setup
68+
with:
69+
cadence_deploy_key: ${{ secrets.CADENCE_DEPLOY_KEY }}
70+
6571
- name: Setup Go
6672
uses: actions/setup-go@v4
6773
timeout-minutes: 10 # fail fast. sometimes this step takes an extremely long time
@@ -139,6 +145,13 @@ jobs:
139145
steps:
140146
- name: Checkout repo
141147
uses: actions/checkout@v3
148+
149+
- name: Setup private build environment
150+
if: ${{ vars.PRIVATE_BUILDS_SUPPORTED == 'true' }}
151+
uses: ./actions/private-setup
152+
with:
153+
cadence_deploy_key: ${{ secrets.CADENCE_DEPLOY_KEY }}
154+
142155
- name: Setup Go
143156
uses: actions/setup-go@v4
144157
timeout-minutes: 10 # fail fast. sometimes this step takes an extremely long time
@@ -178,6 +191,13 @@ jobs:
178191
steps:
179192
- name: Checkout repo
180193
uses: actions/checkout@v3
194+
195+
- name: Setup private build environment
196+
if: ${{ vars.PRIVATE_BUILDS_SUPPORTED == 'true' }}
197+
uses: ./actions/private-setup
198+
with:
199+
cadence_deploy_key: ${{ secrets.CADENCE_DEPLOY_KEY }}
200+
181201
- name: Setup Go
182202
uses: actions/setup-go@v4
183203
timeout-minutes: 10 # fail fast. sometimes this step takes an extremely long time
@@ -216,6 +236,13 @@ jobs:
216236
with:
217237
# all tags are needed for integration tests
218238
fetch-depth: 0
239+
240+
- name: Setup private build environment
241+
if: ${{ vars.PRIVATE_BUILDS_SUPPORTED == 'true' }}
242+
uses: ./actions/private-setup
243+
with:
244+
cadence_deploy_key: ${{ secrets.CADENCE_DEPLOY_KEY }}
245+
219246
- name: Setup Go
220247
uses: actions/setup-go@v4
221248
timeout-minutes: 10 # fail fast. sometimes this step takes an extremely long time
@@ -255,9 +282,17 @@ jobs:
255282
targets: ${{ fromJSON(needs.create-integration-dynamic-test-matrix.outputs.dynamic-matrix)}}
256283
## need to set image explicitly due to GitHub logging issue as described in https://github.com/onflow/flow-go/pull/3087#issuecomment-1234383202
257284
runs-on: ${{ matrix.targets.runner }}
285+
258286
steps:
259287
- name: Checkout repo
260288
uses: actions/checkout@v3
289+
290+
- name: Setup private build environment
291+
if: ${{ vars.PRIVATE_BUILDS_SUPPORTED == 'true' }}
292+
uses: ./actions/private-setup
293+
with:
294+
cadence_deploy_key: ${{ secrets.CADENCE_DEPLOY_KEY }}
295+
261296
- name: Setup Go
262297
uses: actions/setup-go@v4
263298
timeout-minutes: 10 # fail fast. sometimes this step takes an extremely long time
@@ -348,6 +383,13 @@ jobs:
348383
with:
349384
# all tags are needed for integration tests
350385
fetch-depth: 0
386+
387+
- name: Setup private build environment
388+
if: ${{ vars.PRIVATE_BUILDS_SUPPORTED == 'true' }}
389+
uses: ./actions/private-setup
390+
with:
391+
cadence_deploy_key: ${{ secrets.CADENCE_DEPLOY_KEY }}
392+
351393
- name: Setup Go
352394
uses: actions/setup-go@v4
353395
timeout-minutes: 10 # fail fast. sometimes this step takes an extremely long time

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ IMAGE_TAG_ARM := $(IMAGE_TAG)-arm
2626
# Name of the cover profile
2727
COVER_PROFILE := coverage.txt
2828
# Disable go sum database lookup for private repos
29-
GOPRIVATE=github.com/dapperlabs/*
29+
GOPRIVATE=github.com/onflow/*-internal
3030
# OS
3131
UNAME := $(shell uname)
3232

actions/private-setup/action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "Private Build Setup"
2+
description: "Checks and configures the environment for building private dependencies"
3+
inputs:
4+
cadence_deploy_key:
5+
description: "Deploy Key for Private Cadence Repo"
6+
required: true
7+
go_private_value:
8+
description: "The value for GOPRIVATE"
9+
required: false
10+
default: "github.com/onflow/*-internal"
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Load deploy key
15+
uses: webfactory/[email protected]
16+
with:
17+
ssh-private-key: "${{ inputs.cadence_deploy_key }}"
18+
known-hosts: "github.com"
19+
20+
- name: Configure git for SSH
21+
shell: bash
22+
run: |
23+
git config --global url."[email protected]:".insteadOf "https://github.com/"
24+
25+
- name: Configure GOPRIVATE env
26+
shell: bash
27+
run: |
28+
echo "GOPRIVATE=${{ inputs.go_private_value }}" >> $GITHUB_ENV
29+

fvm/evm/handler/blockHashList.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (bhl *BlockHashList) Push(height uint64, bh gethCommon.Hash) error {
8484
if !bhl.IsEmpty() && height != bhl.height+1 {
8585
return fmt.Errorf("out of the order block hash, expected: %d, got: %d", bhl.height+1, height)
8686
}
87+
8788
// updates the block hash stored at index
8889
err := bhl.updateBlockHashAt(bhl.tail, bh)
8990
if err != nil {
@@ -150,16 +151,20 @@ func (bhl *BlockHashList) updateBlockHashAt(idx int, bh gethCommon.Hash) error {
150151
if err != nil {
151152
return err
152153
}
154+
155+
cpy := make([]byte, len(bucket))
156+
copy(cpy, bucket)
157+
153158
// update the block hash
154159
start := (idx % hashCountPerBucket) * hashEncodingSize
155160
end := start + hashEncodingSize
156-
copy(bucket[start:end], bh.Bytes())
161+
copy(cpy[start:end], bh.Bytes())
157162

158163
// store bucket
159164
return bhl.backend.SetValue(
160165
bhl.rootAddress[:],
161166
[]byte(fmt.Sprintf(blockHashListBucketKeyFormat, bucketNumber)),
162-
bucket,
167+
cpy,
163168
)
164169
}
165170

fvm/fvm_test.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package fvm_test
33
import (
44
"context"
55
"crypto/rand"
6+
"encoding/binary"
67
"encoding/hex"
78
"fmt"
89
"math"
@@ -38,6 +39,7 @@ import (
3839
envMock "github.com/onflow/flow-go/fvm/environment/mock"
3940
"github.com/onflow/flow-go/fvm/errors"
4041
"github.com/onflow/flow-go/fvm/evm/events"
42+
"github.com/onflow/flow-go/fvm/evm/handler"
4143
"github.com/onflow/flow-go/fvm/evm/stdlib"
4244
"github.com/onflow/flow-go/fvm/evm/types"
4345
"github.com/onflow/flow-go/fvm/meter"
@@ -3587,3 +3589,106 @@ func Test_MinimumRequiredVersion(t *testing.T) {
35873589
require.Equal(t, cadenceVersion1.String(), getVersion(ctx, snapshotTree))
35883590
}))
35893591
}
3592+
3593+
func Test_BlockHashListShouldWriteOnPush(t *testing.T) {
3594+
3595+
chain := flow.Emulator.Chain()
3596+
sc := systemcontracts.SystemContractsForChain(chain.ChainID())
3597+
3598+
push := func(bhl *handler.BlockHashList, height uint64) {
3599+
buffer := make([]byte, 32)
3600+
pos := 0
3601+
3602+
// encode height as block hash
3603+
binary.BigEndian.PutUint64(buffer[pos:], height)
3604+
err := bhl.Push(height, [32]byte(buffer))
3605+
require.NoError(t, err)
3606+
}
3607+
3608+
t.Run("block hash list write on push", newVMTest().
3609+
withContextOptions(
3610+
fvm.WithChain(chain),
3611+
fvm.WithEVMEnabled(true),
3612+
).
3613+
run(func(
3614+
t *testing.T,
3615+
vm fvm.VM,
3616+
chain flow.Chain,
3617+
ctx fvm.Context,
3618+
snapshotTree snapshot.SnapshotTree,
3619+
) {
3620+
capacity := 256
3621+
3622+
// for the setup we make sure all the block hash list buckets exist
3623+
3624+
ts := state.NewTransactionState(snapshotTree, state.DefaultParameters())
3625+
accounts := environment.NewAccounts(ts)
3626+
envMeter := environment.NewMeter(ts)
3627+
3628+
valueStore := environment.NewValueStore(
3629+
tracing.NewMockTracerSpan(),
3630+
envMeter,
3631+
accounts,
3632+
)
3633+
3634+
bhl, err := handler.NewBlockHashList(valueStore, sc.EVMStorage.Address, capacity)
3635+
require.NoError(t, err)
3636+
3637+
// fill the block hash list
3638+
height := uint64(0)
3639+
for ; height < uint64(capacity); height++ {
3640+
push(bhl, height)
3641+
}
3642+
3643+
es, err := ts.FinalizeMainTransaction()
3644+
require.NoError(t, err)
3645+
snapshotTree = snapshotTree.Append(es)
3646+
3647+
// end of test setup
3648+
3649+
ts = state.NewTransactionState(snapshotTree, state.DefaultParameters())
3650+
accounts = environment.NewAccounts(ts)
3651+
envMeter = environment.NewMeter(ts)
3652+
3653+
valueStore = environment.NewValueStore(
3654+
tracing.NewMockTracerSpan(),
3655+
envMeter,
3656+
accounts,
3657+
)
3658+
3659+
bhl, err = handler.NewBlockHashList(valueStore, sc.EVMStorage.Address, capacity)
3660+
require.NoError(t, err)
3661+
3662+
// after we push the changes should be applied and the first block hash in the bucket should be capacity+1 instead of 0
3663+
push(bhl, height)
3664+
3665+
es, err = ts.FinalizeMainTransaction()
3666+
require.NoError(t, err)
3667+
3668+
// the write set should have both block metadata and block hash list bucket
3669+
require.Len(t, es.WriteSet, 2)
3670+
newBlockHashListBucket, ok := es.WriteSet[flow.NewRegisterID(sc.EVMStorage.Address, "BlockHashListBucket0")]
3671+
require.True(t, ok)
3672+
// full expected block hash list bucket split by individual block hashes
3673+
// first block hash is the capacity+1 instead of 0 (00 00 00 00 00 00 01 00)
3674+
expectedBlockHashListBucket, err := hex.DecodeString(
3675+
"0000000000000100000000000000000000000000000000000000000000000000" +
3676+
"0000000000000001000000000000000000000000000000000000000000000000" +
3677+
"0000000000000002000000000000000000000000000000000000000000000000" +
3678+
"0000000000000003000000000000000000000000000000000000000000000000" +
3679+
"0000000000000004000000000000000000000000000000000000000000000000" +
3680+
"0000000000000005000000000000000000000000000000000000000000000000" +
3681+
"0000000000000006000000000000000000000000000000000000000000000000" +
3682+
"0000000000000007000000000000000000000000000000000000000000000000" +
3683+
"0000000000000008000000000000000000000000000000000000000000000000" +
3684+
"0000000000000009000000000000000000000000000000000000000000000000" +
3685+
"000000000000000a000000000000000000000000000000000000000000000000" +
3686+
"000000000000000b000000000000000000000000000000000000000000000000" +
3687+
"000000000000000c000000000000000000000000000000000000000000000000" +
3688+
"000000000000000d000000000000000000000000000000000000000000000000" +
3689+
"000000000000000e000000000000000000000000000000000000000000000000" +
3690+
"000000000000000f000000000000000000000000000000000000000000000000")
3691+
require.NoError(t, err)
3692+
require.Equal(t, expectedBlockHashListBucket, newBlockHashListBucket)
3693+
}))
3694+
}

0 commit comments

Comments
 (0)