Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LFM Phase-1 #30

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global

mainnet/
node_1/
node_2/
/tmp
*/**/*un~
*/**/*.test
*un~
.DS_Store
*/**/.DS_Store
.ethtest
password.txt
*/**/*tx_database*
*/**/*dapps*
build/_vendor/pkg
Expand Down
1 change: 1 addition & 0 deletions accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func (c *BoundContract) estimateGasLimit(opts *TransactOpts, contract *common.Ad
Value: value,
Data: input,
}
//@lfm: no need for price adjustment here as only invoked via contract-invoked txs
return c.transactor.EstimateGas(ensureContext(opts.Context), msg)
}

Expand Down
1 change: 0 additions & 1 deletion consensus/satoshi/satoshi.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func New(
candidateHubABI: cABI,
signer: types.NewEIP155Signer(chainConfig.ChainID),
}

return c
}

Expand Down
6 changes: 3 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1459,8 +1459,8 @@ func (bc *BlockChain) writeKnownBlock(block *types.Block) error {
return nil
}

// writeBlockWithState writes block, metadata and corresponding state data to the
// database.
// writeBlockWithState writes block, metadata and corresponding state data to the database
// @lfm commit a new block
func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB) error {
// Calculate the total difficulty of the block
ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
Expand Down Expand Up @@ -1599,7 +1599,7 @@ func (bc *BlockChain) WriteBlockAndSetHead(block *types.Block, receipts []*types
return bc.writeBlockAndSetHead(block, receipts, logs, state, emitHeadEvent)
}

// writeBlockAndSetHead writes the block and all associated state to the database,
// writeBlockAndSetHead writes the block and all associated state to the database, @lfm
// and also it applies the given block as the new chain head. This function expects
// the chain mutex to be held.
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
Expand Down
1 change: 1 addition & 0 deletions core/types/access_list_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (tx *AccessListTx) accessList() AccessList { return tx.AccessList }
func (tx *AccessListTx) data() []byte { return tx.Data }
func (tx *AccessListTx) gas() uint64 { return tx.Gas }
func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice }
func (tx *AccessListTx) origGasPrice() *big.Int { return nil }
func (tx *AccessListTx) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *AccessListTx) value() *big.Int { return tx.Value }
Expand Down
1 change: 1 addition & 0 deletions core/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
func (tx *DynamicFeeTx) origGasPrice() *big.Int { return nil }
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }
func (tx *DynamicFeeTx) to() *common.Address { return tx.To }
Expand Down
3 changes: 3 additions & 0 deletions core/types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@

// LegacyTx is the transaction data of regular Ethereum transactions.
type LegacyTx struct {
Nonce uint64 // nonce of sender account

Check failure on line 27 in core/types/legacy_tx.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.19.x, ubuntu-latest)

File is not `goimports`-ed (goimports)
GasPrice *big.Int // wei per gas
Gas uint64 // gas limit
To *common.Address `rlp:"nil"` // nil means contract creation
Value *big.Int // wei amount
Data []byte // contract invocation input data
V, R, S *big.Int // signature values
OrigGasPrice *big.Int `rlp:"optional"` //@lfm
}

// NewTransaction creates an unsigned legacy transaction.
Expand Down Expand Up @@ -71,6 +72,7 @@
V: new(big.Int),
R: new(big.Int),
S: new(big.Int),
OrigGasPrice: tx.OrigGasPrice,
}
if tx.Value != nil {
cpy.Value.Set(tx.Value)
Expand All @@ -97,6 +99,7 @@
func (tx *LegacyTx) data() []byte { return tx.Data }
func (tx *LegacyTx) gas() uint64 { return tx.Gas }
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) origGasPrice() *big.Int { return tx.OrigGasPrice }
func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
func (tx *LegacyTx) value() *big.Int { return tx.Value }
Expand Down
19 changes: 19 additions & 0 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth/gasprice/lfm"
"github.com/ethereum/go-ethereum/rlp"
)

Expand Down Expand Up @@ -77,6 +78,7 @@ type TxData interface {
data() []byte
gas() uint64
gasPrice() *big.Int
origGasPrice() *big.Int
gasTipCap() *big.Int
gasFeeCap() *big.Int
value() *big.Int
Expand Down Expand Up @@ -165,6 +167,11 @@ func (tx *Transaction) UnmarshalBinary(b []byte) error {
if err != nil {
return err
}
//@lfm RPC invocation route: adjust tx gas price
if data.OrigGasPrice == nil {
data.OrigGasPrice = data.GasPrice
data.GasPrice = lfm.AdjustGasPrice(data.Gas, data.Value, data.To, data.Data, data.OrigGasPrice)
}
tx.setDecoded(&data, len(b))
return nil
}
Expand Down Expand Up @@ -274,6 +281,14 @@ func (tx *Transaction) Gas() uint64 { return tx.inner.gas() }
// GasPrice returns the gas price of the transaction.
func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.inner.gasPrice()) }

func (tx *Transaction) OrigGasPrice() *big.Int {
orig := tx.inner.origGasPrice()
if orig == nil {
return nil
}
return new(big.Int).Set(orig)
}

// GasTipCap returns the gasTipCap per gas of the transaction.
func (tx *Transaction) GasTipCap() *big.Int { return new(big.Int).Set(tx.inner.gasTipCap()) }

Expand Down Expand Up @@ -332,6 +347,10 @@ func (tx *Transaction) GasTipCapCmp(other *Transaction) int {

// GasTipCapIntCmp compares the gasTipCap of the transaction against the given gasTipCap.
func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int {
legacyTx, isLegacy := tx.inner.(*LegacyTx) //@lfm
if isLegacy && legacyTx.origGasPrice() != nil {
return legacyTx.origGasPrice().Cmp(other) // tx gas price might have been reduced by the lfm module
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
return tx.inner.gasTipCap().Cmp(other)
}

Expand Down
3 changes: 3 additions & 0 deletions core/types/transaction_marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
AccessList *AccessList `json:"accessList,omitempty"`

// Only used for encoding:
Hash common.Hash `json:"hash"`

Check failure on line 50 in core/types/transaction_marshalling.go

View workflow job for this annotation

GitHub Actions / golang-lint (1.19.x, ubuntu-latest)

File is not `goimports`-ed (goimports)
OrigGasPrice *hexutil.Big `json:"origGasPrice" rlp:"optional"`
}

// MarshalJSON marshals as JSON with a hash.
Expand All @@ -63,6 +64,7 @@
enc.Nonce = (*hexutil.Uint64)(&tx.Nonce)
enc.Gas = (*hexutil.Uint64)(&tx.Gas)
enc.GasPrice = (*hexutil.Big)(tx.GasPrice)
enc.OrigGasPrice = (*hexutil.Big)(tx.OrigGasPrice)
enc.Value = (*hexutil.Big)(tx.Value)
enc.Data = (*hexutil.Bytes)(&tx.Data)
enc.To = t.To()
Expand Down Expand Up @@ -122,6 +124,7 @@
return errors.New("missing required field 'gasPrice' in transaction")
}
itx.GasPrice = (*big.Int)(dec.GasPrice)
itx.OrigGasPrice = (*big.Int)(dec.OrigGasPrice)
if dec.Gas == nil {
return errors.New("missing required field 'gas' in transaction")
}
Expand Down
22 changes: 19 additions & 3 deletions core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,15 @@ func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error) {
V, R, S := tx.RawSignatureValues()
V = new(big.Int).Sub(V, s.chainIdMul)
V.Sub(V, big8)
return recoverPlain(s.Hash(tx), R, S, V, true)
//@lfm: crypto calc to obtain via tx hash the sender address
var sighash common.Hash
legacyTx, isLegacy := tx.inner.(*LegacyTx)
if isLegacy && legacyTx.origGasPrice() != nil {
sighash = s.RecoveryHash(tx, legacyTx.origGasPrice())
} else {
sighash = s.Hash(tx)
}
return recoverPlain(sighash, R, S, V, true)
}

// SignatureValues returns signature values. This signature
Expand All @@ -386,12 +394,20 @@ func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big
return R, S, V, nil
}

func (s EIP155Signer) RecoveryHash(tx *Transaction, origGasPrice *big.Int) common.Hash { //@lfm
return s.hashImpl(tx, origGasPrice)
}

func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
return s.hashImpl(tx, tx.GasPrice())
}

// Hash returns the hash to be signed by the sender.
// It does not uniquely identify the transaction.
func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
func (s EIP155Signer) hashImpl(tx *Transaction, gasPrice *big.Int) common.Hash {
return rlpHash([]interface{}{
tx.Nonce(),
tx.GasPrice(),
gasPrice,
tx.Gas(),
tx.To(),
tx.Value(),
Expand Down
2 changes: 2 additions & 0 deletions debug_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
go build -o ./build/bin/geth -gcflags=all='-N -l' -v ./cmd/geth
Loading
Loading