Skip to content

Commit 3e1eef9

Browse files
authored
Merge pull request #7748 from onflow/feature/malleability
Feature: Malleability
2 parents 3c0df29 + 95b5b10 commit 3e1eef9

File tree

803 files changed

+21967
-18107
lines changed

Some content is hidden

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

803 files changed

+21967
-18107
lines changed

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ issues:
4646
- path: 'utils/unittest/*' # disable some linters on test files
4747
linters:
4848
- structwrite
49+
- path: 'consensus/hotstuff/helper/*' # disable some linters on test files
50+
linters:
51+
- structwrite
52+
- path: 'engine/execution/testutil/*' # disable some linters on test files
53+
linters:
54+
- structwrite
4955
# typecheck currently not handling the way we do function inheritance well
5056
# disabling for now
5157
- path: 'cmd/access/node_build/*'

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ generate-fvm-env-wrappers:
155155
.PHONY: generate-mocks
156156
generate-mocks: install-mock-generators
157157
mockery --name '(Connector|PingInfoProvider)' --dir=network/p2p --case=underscore --output="./network/mocknetwork" --outpkg="mocknetwork"
158-
CGO_CFLAGS=$(CRYPTO_FLAG) mockgen -destination=storage/mocks/storage.go -package=mocks github.com/onflow/flow-go/storage Blocks,Headers,Payloads,Collections,Commits,Events,ServiceEvents,TransactionResults
159158
CGO_CFLAGS=$(CRYPTO_FLAG) mockgen -destination=network/mocknetwork/mock_network.go -package=mocknetwork github.com/onflow/flow-go/network EngineRegistry
160159
mockery --name=ExecutionDataStore --dir=module/executiondatasync/execution_data --case=underscore --output="./module/executiondatasync/execution_data/mock" --outpkg="mock"
161160
mockery --name=Downloader --dir=module/executiondatasync/execution_data --case=underscore --output="./module/executiondatasync/execution_data/mock" --outpkg="mock"

access/legacy/convert/convert.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/onflow/crypto/hash"
99
accessproto "github.com/onflow/flow/protobuf/go/flow/legacy/access"
1010
entitiesproto "github.com/onflow/flow/protobuf/go/flow/legacy/entities"
11-
"google.golang.org/protobuf/types/known/timestamppb"
1211

1312
"github.com/onflow/flow-go/engine/common/rpc/convert"
1413
accessmodel "github.com/onflow/flow-go/model/access"
@@ -18,60 +17,64 @@ import (
1817
var ErrEmptyMessage = errors.New("protobuf message is empty")
1918

2019
func MessageToTransaction(m *entitiesproto.Transaction, chain flow.Chain) (flow.TransactionBody, error) {
20+
var t flow.TransactionBody
2121
if m == nil {
22-
return flow.TransactionBody{}, ErrEmptyMessage
22+
return t, ErrEmptyMessage
2323
}
2424

25-
t := flow.NewTransactionBody()
26-
25+
tb := flow.NewTransactionBodyBuilder()
2726
proposalKey := m.GetProposalKey()
2827
if proposalKey != nil {
2928
proposalAddress, err := convert.Address(proposalKey.GetAddress(), chain)
3029
if err != nil {
31-
return *t, err
30+
return t, err
3231
}
33-
t.SetProposalKey(proposalAddress, proposalKey.GetKeyId(), proposalKey.GetSequenceNumber())
32+
tb.SetProposalKey(proposalAddress, proposalKey.GetKeyId(), proposalKey.GetSequenceNumber())
3433
}
3534

3635
payer := m.GetPayer()
3736
if payer != nil {
3837
payerAddress, err := convert.Address(payer, chain)
3938
if err != nil {
40-
return *t, err
39+
return t, err
4140
}
42-
t.SetPayer(payerAddress)
41+
tb.SetPayer(payerAddress)
4342
}
4443

4544
for _, authorizer := range m.GetAuthorizers() {
4645
authorizerAddress, err := convert.Address(authorizer, chain)
4746
if err != nil {
48-
return *t, err
47+
return t, err
4948
}
50-
t.AddAuthorizer(authorizerAddress)
49+
tb.AddAuthorizer(authorizerAddress)
5150
}
5251

5352
for _, sig := range m.GetPayloadSignatures() {
5453
addr, err := convert.Address(sig.GetAddress(), chain)
5554
if err != nil {
56-
return *t, err
55+
return t, err
5756
}
58-
t.AddPayloadSignature(addr, sig.GetKeyId(), sig.GetSignature())
57+
tb.AddPayloadSignature(addr, sig.GetKeyId(), sig.GetSignature())
5958
}
6059

6160
for _, sig := range m.GetEnvelopeSignatures() {
6261
addr, err := convert.Address(sig.GetAddress(), chain)
6362
if err != nil {
64-
return *t, err
63+
return t, err
6564
}
66-
t.AddEnvelopeSignature(addr, sig.GetKeyId(), sig.GetSignature())
65+
tb.AddEnvelopeSignature(addr, sig.GetKeyId(), sig.GetSignature())
6766
}
6867

69-
t.SetScript(m.GetScript())
70-
t.SetArguments(m.GetArguments())
71-
t.SetReferenceBlockID(flow.HashToID(m.GetReferenceBlockId()))
72-
t.SetComputeLimit(m.GetGasLimit())
68+
transactionBody, err := tb.SetScript(m.GetScript()).
69+
SetArguments(m.GetArguments()).
70+
SetReferenceBlockID(flow.HashToID(m.GetReferenceBlockId())).
71+
SetComputeLimit(m.GetGasLimit()).
72+
Build()
73+
if err != nil {
74+
return t, fmt.Errorf("could not build transaction body: %w", err)
75+
}
7376

74-
return *t, nil
77+
return *transactionBody, nil
7578
}
7679

7780
func TransactionToMessage(tb flow.TransactionBody) *entitiesproto.Transaction {
@@ -131,22 +134,17 @@ func TransactionResultToMessage(result accessmodel.TransactionResult) *accesspro
131134
func BlockHeaderToMessage(h *flow.Header) (*entitiesproto.BlockHeader, error) {
132135
id := h.ID()
133136

134-
t := timestamppb.New(h.Timestamp)
135-
136137
return &entitiesproto.BlockHeader{
137138
Id: id[:],
138139
ParentId: h.ParentID[:],
139140
Height: h.Height,
140-
Timestamp: t,
141+
Timestamp: convert.BlockTimestamp2ProtobufTime(h.Timestamp),
141142
}, nil
142143
}
143144

144145
func BlockToMessage(h *flow.Block) (*entitiesproto.Block, error) {
145146
id := h.ID()
146147

147-
parentID := h.Header.ParentID
148-
t := timestamppb.New(h.Header.Timestamp)
149-
150148
cg := make([]*entitiesproto.CollectionGuarantee, len(h.Payload.Guarantees))
151149
for i, g := range h.Payload.Guarantees {
152150
cg[i] = collectionGuaranteeToMessage(g)
@@ -159,22 +157,20 @@ func BlockToMessage(h *flow.Block) (*entitiesproto.Block, error) {
159157

160158
bh := entitiesproto.Block{
161159
Id: id[:],
162-
Height: h.Header.Height,
163-
ParentId: parentID[:],
164-
Timestamp: t,
160+
Height: h.Height,
161+
ParentId: h.ParentID[:],
162+
Timestamp: convert.BlockTimestamp2ProtobufTime(h.Timestamp),
165163
CollectionGuarantees: cg,
166164
BlockSeals: seals,
167-
Signatures: [][]byte{h.Header.ParentVoterSigData},
165+
Signatures: [][]byte{h.ParentVoterSigData},
168166
}
169167

170168
return &bh, nil
171169
}
172170

173171
func collectionGuaranteeToMessage(g *flow.CollectionGuarantee) *entitiesproto.CollectionGuarantee {
174-
id := g.ID()
175-
176172
return &entitiesproto.CollectionGuarantee{
177-
CollectionId: id[:],
173+
CollectionId: IdentifierToMessage(g.CollectionID),
178174
Signatures: [][]byte{g.Signature},
179175
}
180176
}

access/mock/api.go

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

admin/commands/common/read_protocol_state_blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (r *ReadProtocolStateBlocksCommand) Handler(_ context.Context, req *admin.C
122122
}
123123

124124
result = append(result, block)
125-
firstHeight := int64(block.Header.Height)
125+
firstHeight := int64(block.Height)
126126

127127
for height := firstHeight - 1; height >= 0 && height > firstHeight-int64(data.numBlocksToQuery); height-- {
128128
block, err = r.getBlockByHeight(uint64(height))

admin/commands/common/read_protocol_state_blocks_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,28 @@ func (suite *ReadProtocolStateBlocksSuite) SetupTest() {
5555

5656
var blocks []*flow.Block
5757

58-
genesis := unittest.GenesisFixture()
58+
genesis := unittest.Block.Genesis(flow.Emulator)
5959
blocks = append(blocks, genesis)
60-
sealed := unittest.BlockWithParentFixture(genesis.Header)
60+
sealed := unittest.BlockWithParentFixture(genesis.ToHeader())
6161
blocks = append(blocks, sealed)
62-
final := unittest.BlockWithParentFixture(sealed.Header)
62+
final := unittest.BlockWithParentFixture(sealed.ToHeader())
6363
blocks = append(blocks, final)
64-
final = unittest.BlockWithParentFixture(final.Header)
64+
final = unittest.BlockWithParentFixture(final.ToHeader())
6565
blocks = append(blocks, final)
66-
final = unittest.BlockWithParentFixture(final.Header)
66+
final = unittest.BlockWithParentFixture(final.ToHeader())
6767
blocks = append(blocks, final)
6868

6969
suite.allBlocks = blocks
7070
suite.sealed = sealed
7171
suite.final = final
7272

73-
suite.state.On("Final").Return(createSnapshot(final.Header))
74-
suite.state.On("Sealed").Return(createSnapshot(sealed.Header))
73+
suite.state.On("Final").Return(createSnapshot(final.ToHeader()))
74+
suite.state.On("Sealed").Return(createSnapshot(sealed.ToHeader()))
7575
suite.state.On("AtBlockID", mock.Anything).Return(
7676
func(blockID flow.Identifier) protocol.Snapshot {
7777
for _, block := range blocks {
7878
if block.ID() == blockID {
79-
return createSnapshot(block.Header)
79+
return createSnapshot(block.ToHeader())
8080
}
8181
}
8282
return invalid.NewSnapshot(fmt.Errorf("invalid block ID: %v", blockID))
@@ -86,7 +86,7 @@ func (suite *ReadProtocolStateBlocksSuite) SetupTest() {
8686
func(height uint64) protocol.Snapshot {
8787
if int(height) < len(blocks) {
8888
block := blocks[height]
89-
return createSnapshot(block.Header)
89+
return createSnapshot(block.ToHeader())
9090
}
9191
return invalid.NewSnapshot(fmt.Errorf("invalid height: %v", height))
9292
},

admin/commands/execution/stop_at_height_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestCommandsSetsValues(t *testing.T) {
9999
nil,
100100
nil,
101101
nil,
102-
&flow.Header{Height: 1},
102+
&flow.Header{HeaderBody: flow.HeaderBody{Height: 1}},
103103
false,
104104
false,
105105
)

0 commit comments

Comments
 (0)