Skip to content

Commit

Permalink
Merge pull request ethereum#1230 from maticnetwork/v1.3.1
Browse files Browse the repository at this point in the history
v1.3.1 Stable Release
  • Loading branch information
anshalshukla authored Apr 29, 2024
2 parents 46f93b1 + c56d933 commit b8ad000
Show file tree
Hide file tree
Showing 40 changed files with 477 additions and 111 deletions.
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
skip-files:
- core/genesis_alloc.go

linters:
disable-all: true
Expand Down Expand Up @@ -44,6 +42,8 @@ linters-settings:
min-occurrences: 6 # minimum number of occurrences

issues:
exclude-files:
- core/genesis_alloc.go
exclude-rules:
- path: crypto/bn256/cloudflare/optate.go
linters:
Expand All @@ -64,4 +64,4 @@ issues:
- 'SA1029: should not use built-in type string as key for value'
- 'SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details'
- 'SA1019: grpc.WithInsecure is deprecated: use WithTransportCredentials and insecure.NewCredentials() instead. Will be supported throughout 1.x'
- "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate"
- "SA1019: rand.Read has been deprecated since Go 1.20 because it shouldn't be used: For almost all use cases, crypto/rand.Read is more appropriate"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ lint:

lintci-deps:
rm -f ./build/bin/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.53.3
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./build/bin v1.57.2

goimports:
goimports -local "$(PACKAGE)" -w .
Expand Down
3 changes: 2 additions & 1 deletion accounts/abi/bind/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/params"
)

var testKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
Expand Down Expand Up @@ -64,7 +65,7 @@ func TestWaitDeployed(t *testing.T) {

// Create the transaction
head, _ := backend.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))

tx := types.NewContractCreation(0, big.NewInt(0), test.gas, gasPrice, common.FromHex(test.code))
tx, _ = types.SignTx(tx, types.HomesteadSigner{}, testKey)
Expand Down
Binary file added audit/audit-feature-milestones.pdf
Binary file not shown.
4 changes: 4 additions & 0 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,10 @@ func (c *Bor) changeContractCodeIfNeeded(headerNumber uint64, state *state.State
for addr, account := range allocs {
log.Info("change contract code", "address", addr)
state.SetCode(addr, account.Code)

if state.GetBalance(addr).Cmp(big.NewInt(0)) == 0 {
state.SetBalance(addr, account.Balance)
}
}
}
}
Expand Down
31 changes: 24 additions & 7 deletions consensus/bor/bor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func TestGenesisContractChange(t *testing.T) {
"balance": "0x1000",
},
},
"6": map[string]interface{}{
addr0.Hex(): map[string]interface{}{
"code": hexutil.Bytes{0x1, 0x4},
"balance": "0x2000",
},
},
},
},
}
Expand Down Expand Up @@ -87,24 +93,35 @@ func TestGenesisContractChange(t *testing.T) {

root := genesis.Root()

// code does not change
// code does not change, balance remains 0
root, statedb = addBlock(root, 1)
require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x1})
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0))

// code changes 1st time
// code changes 1st time, balance remains 0
root, statedb = addBlock(root, 2)
require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x2})
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0))

// code same as 1st change
// code same as 1st change, balance remains 0
root, statedb = addBlock(root, 3)
require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x2})
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0))

// code changes 2nd time
_, statedb = addBlock(root, 4)
// code changes 2nd time, balance updates to 4096
root, statedb = addBlock(root, 4)
require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x3})
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096))

// make sure balance change DOES NOT take effect
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(0))
// code same as 2nd change, balance remains 4096
root, statedb = addBlock(root, 5)
require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x3})
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096))

// code changes 3rd time, balance remains 4096
_, statedb = addBlock(root, 6)
require.Equal(t, statedb.GetCode(addr0), []byte{0x1, 0x4})
require.Equal(t, statedb.GetBalance(addr0), big.NewInt(4096))
}

func TestEncodeSigHeaderJaipur(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion consensus/bor/valset/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func verifyUpdates(updates []*Validator, vals *ValidatorSet) (updatedTotalVoting
_, val := vals.GetByAddress(address)

if val == nil {
// New validator, add its voting power the the total.
// New validator, add its voting power the total.
updatedTotalVotingPower += valUpdate.VotingPower
numNewValidators++
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/blockstm/mvhashmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestMVHashMapBasics(t *testing.T) {
mvh.Write(ap1, Version{10, 1}, valueFor(10, 1))

res = mvh.Read(ap1, 9)
require.Equal(t, -1, res.depIdx, "reads that should go the the DB return dependency -1")
require.Equal(t, -1, res.depIdx, "reads that should go the DB return dependency -1")
res = mvh.Read(ap1, 10)
require.Equal(t, -1, res.depIdx, "Read returns entries from smaller txns, not txn 10")

Expand Down
16 changes: 14 additions & 2 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ var DefaultConfig = Config{
AccountQueue: 64,
GlobalQueue: 1024,

Lifetime: 3 * time.Hour,
Lifetime: 3 * time.Hour,
AllowUnprotectedTxs: false,
}

// sanitize checks the provided user configurations and changes anything that's
Expand Down Expand Up @@ -601,7 +602,8 @@ func (pool *LegacyPool) local() map[common.Address]types.Transactions {
// and does not require the pool mutex to be held.
func (pool *LegacyPool) validateTxBasics(tx *types.Transaction, local bool) error {
opts := &txpool.ValidationOptions{
Config: pool.chainconfig,
Config: pool.chainconfig,
AllowUnprotectedTxs: pool.config.AllowUnprotectedTxs,
Accept: 0 |
1<<types.LegacyTxType |
1<<types.AccessListTxType |
Expand Down Expand Up @@ -671,6 +673,11 @@ func (pool *LegacyPool) add(tx *types.Transaction, local bool) (replaced bool, e
knownTxMeter.Mark(1)
return false, txpool.ErrAlreadyKnown
}

if pool.config.AllowUnprotectedTxs {
pool.signer = types.NewFakeSigner(tx.ChainId())
}

// Make the local flag. If it's from local source or it's from the network but
// the sender is marked as local previously, treat it as the local transaction.
isLocal := local || pool.locals.containsTx(tx)
Expand Down Expand Up @@ -984,6 +991,11 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, local, sync bool) []error
knownTxMeter.Mark(1)
continue
}

if pool.config.AllowUnprotectedTxs {
pool.signer = types.NewFakeSigner(tx.ChainId())
}

// Exclude transactions with basic errors, e.g invalid signatures and
// insufficient intrinsic gas as soon as possible and cache senders
// in transactions before obtaining lock
Expand Down
7 changes: 4 additions & 3 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package legacypool

import (
"crypto/ecdsa"
crand "crypto/rand"
"errors"
"fmt"
"io"
Expand All @@ -30,7 +31,7 @@ import (
"time"

"github.com/holiman/uint256"
"github.com/maticnetwork/crand"
crand2 "github.com/maticnetwork/crand"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -115,7 +116,7 @@ func pricedTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ec

func pricedDataTransaction(nonce uint64, gaslimit uint64, gasprice *big.Int, key *ecdsa.PrivateKey, bytes uint64) *types.Transaction {
data := make([]byte, bytes)
rand.Read(data)
crand.Read(data)

tx, _ := types.SignTx(types.NewTransaction(nonce, common.Address{}, big.NewInt(0), gaslimit, gasprice, data), types.HomesteadSigner{}, key)

Expand Down Expand Up @@ -3801,7 +3802,7 @@ func BenchmarkBigs(b *testing.B) {
var over bool

for i := 0; i < len(ints); i++ {
ints[i] = crand.BigInt(max)
ints[i] = crand2.BigInt(max)
intUs[i], over = uint256.FromBig(ints[i])

if over {
Expand Down
4 changes: 3 additions & 1 deletion core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
type ValidationOptions struct {
Config *params.ChainConfig // Chain configuration to selectively validate based on current fork rules

AllowUnprotectedTxs bool // Whether to allow unprotected transactions in the pool

Accept uint8 // Bitmap of transaction types that should be accepted for the calling pool
MaxSize uint64 // Maximum size of a transaction that the caller can meaningfully handle
MinTip *big.Int // Minimum gas tip needed to allow a transaction into the caller pool
Expand Down Expand Up @@ -91,7 +93,7 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types
return core.ErrTipAboveFeeCap
}
// Make sure the transaction is signed properly
if _, err := types.Sender(signer, tx); err != nil {
if _, err := types.Sender(signer, tx); err != nil && !opts.AllowUnprotectedTxs {
return ErrInvalidSender
}
// Ensure the transaction has more gas than the bare minimum needed to cover
Expand Down
35 changes: 35 additions & 0 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,38 @@ func deriveChainId(v *big.Int) *big.Int {
v = new(big.Int).Sub(v, big.NewInt(35))
return v.Div(v, big.NewInt(2))
}

// FakeSigner implements the Signer interface and accepts unprotected transactions
type FakeSigner struct{ londonSigner }

var _ Signer = FakeSigner{}

func NewFakeSigner(chainId *big.Int) Signer {
signer := NewLondonSigner(chainId)
ls, _ := signer.(londonSigner)
return FakeSigner{londonSigner: ls}
}

func (f FakeSigner) Sender(tx *Transaction) (common.Address, error) {
return f.londonSigner.Sender(tx)
}

func (f FakeSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error) {
return f.londonSigner.SignatureValues(tx, sig)
}

func (f FakeSigner) ChainID() *big.Int {
return f.londonSigner.ChainID()
}

// Hash returns 'signature hash', i.e. the transaction hash that is signed by the
// private key. This hash does not uniquely identify the transaction.
func (f FakeSigner) Hash(tx *Transaction) common.Hash {
return f.londonSigner.Hash(tx)
}

// Equal returns true if the given signer is the same as the receiver.
func (f FakeSigner) Equal(Signer) bool {
// Always return true
return true
}
1 change: 1 addition & 0 deletions eth/api_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
api.e.lock.Unlock()

api.e.txPool.SetGasTip((*big.Int)(&gasPrice))
api.e.Miner().SetGasTip((*big.Int)(&gasPrice))
return true
}

Expand Down
10 changes: 7 additions & 3 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
if eth.APIBackend.allowUnprotectedTxs {
log.Debug(" ###########", "Unprotected transactions allowed")

log.Info("------Unprotected transactions allowed-------")
config.TxPool.AllowUnprotectedTxs = true
}

Expand Down Expand Up @@ -822,6 +821,12 @@ func (s *Ethereum) Stop() error {
// Stop all the peer-related stuff first.
s.ethDialCandidates.Close()
s.snapDialCandidates.Close()

// Close the engine before handler else it may cause a deadlock where
// the heimdall is unresponsive and the syncing loop keeps waiting
// for a response and is unable to proceed to exit `Finalize` during
// block processing.
s.engine.Close()
s.handler.Stop()

// Then stop everything else.
Expand All @@ -834,7 +839,6 @@ func (s *Ethereum) Stop() error {
s.txPool.Close()
s.miner.Close()
s.blockchain.Stop()
s.engine.Close()

// Clean shutdown marker as the last thing before closing db
s.shutdownTracker.Stop()
Expand Down
15 changes: 0 additions & 15 deletions eth/bor_api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,6 @@ func (b *EthAPIBackend) GetVoteOnHash(ctx context.Context, starBlockNr uint64, e
return false, fmt.Errorf("Hash mismatch: localChainHash %s, milestoneHash %s", localEndBlockHash, hash)
}

ethHandler := (*ethHandler)(b.eth.handler)

bor, ok := ethHandler.chain.Engine().(*bor.Bor)

if !ok {
return false, fmt.Errorf("Bor not available")
}

err = bor.HeimdallClient.FetchMilestoneID(ctx, milestoneId)

if err != nil {
downloader.UnlockMutex(false, "", endBlockNr, common.Hash{})
return false, fmt.Errorf("Milestone ID doesn't exist in Heimdall")
}

downloader.UnlockMutex(true, milestoneId, endBlockNr, localEndBlock.Hash())

return true, nil
Expand Down
Loading

0 comments on commit b8ad000

Please sign in to comment.