Skip to content

Commit

Permalink
Fix panic when unsigned transaction is sent to txrelayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Feb 12, 2024
1 parent d579f1e commit 54f698f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions archive/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func Test_processExportStream(t *testing.T) {
if rv.err != nil {
break
}

expectedData = append(expectedData, rv.event.Data...)
}
assert.Equal(t, expectedData, buffer.Bytes())
Expand Down
4 changes: 4 additions & 0 deletions consensus/polybft/checkpoint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func TestCheckpointManager_abiEncodeCheckpointBlock(t *testing.T) {

currentValidators.IterAcct(nil, func(v *validator.TestValidator) {
signatures = append(signatures, v.MustSign(proposalHash, signer.DomainCheckpointManager))

bmp.Set(i)
i++
})
Expand Down Expand Up @@ -246,6 +247,7 @@ func TestCheckpointManager_getCurrentCheckpointID(t *testing.T) {
txRelayerMock.On("Call", mock.Anything, mock.Anything, mock.Anything).
Return(c.checkpointID, c.returnError).
Once()

acc, err := wallet.GenerateAccount()
require.NoError(t, err)

Expand All @@ -254,6 +256,7 @@ func TestCheckpointManager_getCurrentCheckpointID(t *testing.T) {
key: acc.Ecdsa,
logger: hclog.NewNullLogger(),
}

actualCheckpointID, err := getCurrentCheckpointBlock(checkpointMgr.rootChainRelayer,
checkpointMgr.checkpointManagerAddr)
if c.errSubstring == "" {
Expand Down Expand Up @@ -418,6 +421,7 @@ func TestCheckpointManager_GenerateExitProof(t *testing.T) {

// copy and make proof invalid
invalidProof := make([]types.Hash, len(proof.Data))

copy(invalidProof, proof.Data)
invalidProof[0][0]++

Expand Down
4 changes: 3 additions & 1 deletion consensus/polybft/extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,15 @@ func TestExtra_InitGenesisValidatorsDelta(t *testing.T) {
Removed: bitmap.Bitmap{},
}

var i int
i := 0

for _, val := range vals.Validators {
delta.Added[i] = &validator.ValidatorMetadata{
Address: types.Address(val.Account.Ecdsa.Address()),
BlsKey: val.Account.Bls.PublicKey(),
VotingPower: new(big.Int).SetUint64(val.VotingPower),
}

i++
}

Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/governance_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func TestGovernanceManager_PostBlock(t *testing.T) {
governanceManager, err := newGovernanceManager(chainParams, genesisPolybftConfig,
hclog.NewNullLogger(), state, blockchainMock, nil)
require.NoError(t, err)

// this cheats that we have this fork in code
governanceManager.allForksHashes[newForkHash] = newForkName
require.NoError(t, state.GovernanceStore.insertGovernanceEvent(1, newForkBlock.Uint64(),
Expand Down
1 change: 1 addition & 0 deletions consensus/polybft/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func (m *systemStateMock) GetEpoch() (uint64, error) {
return epochNumber, nil
} else if len(args) == 2 {
epochNumber, _ := args.Get(0).(uint64)

err, ok := args.Get(1).(error)
if ok {
return epochNumber, err
Expand Down
3 changes: 3 additions & 0 deletions consensus/polybft/stake_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
fullValidatorSet := validators.GetPublicIdentities().Copy()
validatorToUpdate := fullValidatorSet[2]
validatorToUpdate.VotingPower = big.NewInt(5)

require.NoError(t, state.StakeStore.insertFullValidatorSet(validatorSetState{
Validators: newValidatorStakeMap(fullValidatorSet),
}, nil))
Expand All @@ -306,6 +307,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
fullValidatorSet := validators.GetPublicIdentities().Copy()
validatorToUpdate := fullValidatorSet[3]
validatorToUpdate.VotingPower = bigZero

require.NoError(t, state.StakeStore.insertFullValidatorSet(validatorSetState{
Validators: newValidatorStakeMap(fullValidatorSet),
}, nil))
Expand All @@ -321,6 +323,7 @@ func TestStakeManager_UpdateValidatorSet(t *testing.T) {
fullValidatorSet := validators.GetPublicIdentities().Copy()
validatorsToUpdate := fullValidatorSet[4]
validatorsToUpdate.VotingPower = bigZero

require.NoError(t, state.StakeStore.insertFullValidatorSet(validatorSetState{
Validators: newValidatorStakeMap(fullValidatorSet),
}, nil))
Expand Down
18 changes: 15 additions & 3 deletions txrelayer/txrelayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ func convertTxn(tx *types.Transaction) *ethgo.Transaction {
})
}

var (
vRaw []byte
rRaw []byte
sRaw []byte
)

if v != nil && r != nil && s != nil {
vRaw = v.Bytes()
rRaw = r.Bytes()
sRaw = s.Bytes()
}

return &ethgo.Transaction{
Hash: ethgo.Hash(tx.Hash()),
From: ethgo.Address(tx.From()),
Expand All @@ -332,9 +344,9 @@ func convertTxn(tx *types.Transaction) *ethgo.Transaction {
Gas: tx.Gas(),
Value: tx.Value(),
Nonce: tx.Nonce(),
V: v.Bytes(),
R: r.Bytes(),
S: s.Bytes(),
V: vRaw,
R: rRaw,
S: sRaw,
ChainID: tx.ChainID(),
AccessList: accessList,
MaxPriorityFeePerGas: tx.GasTipCap(),
Expand Down

0 comments on commit 54f698f

Please sign in to comment.