-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from multiversx/rc/spica-patch-mempool
Rc/spica patch mempool
- Loading branch information
Showing
44 changed files
with
2,913 additions
and
3,261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package txcachemocks | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/data" | ||
) | ||
|
||
// MempoolHostMock - | ||
type MempoolHostMock struct { | ||
minGasLimit uint64 | ||
minGasPrice uint64 | ||
gasPerDataByte uint64 | ||
gasPriceModifier float64 | ||
|
||
ComputeTxFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int | ||
GetTransferredValueCalled func(tx data.TransactionHandler) *big.Int | ||
} | ||
|
||
// NewMempoolHostMock - | ||
func NewMempoolHostMock() *MempoolHostMock { | ||
return &MempoolHostMock{ | ||
minGasLimit: 50000, | ||
minGasPrice: 1000000000, | ||
gasPerDataByte: 1500, | ||
gasPriceModifier: 0.01, | ||
} | ||
} | ||
|
||
// ComputeTxFee - | ||
func (mock *MempoolHostMock) ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int { | ||
if mock.ComputeTxFeeCalled != nil { | ||
return mock.ComputeTxFeeCalled(tx) | ||
} | ||
|
||
dataLength := uint64(len(tx.GetData())) | ||
gasPriceForMovement := tx.GetGasPrice() | ||
gasPriceForProcessing := uint64(float64(gasPriceForMovement) * mock.gasPriceModifier) | ||
|
||
gasLimitForMovement := mock.minGasLimit + dataLength*mock.gasPerDataByte | ||
if tx.GetGasLimit() < gasLimitForMovement { | ||
panic("tx.GetGasLimit() < gasLimitForMovement") | ||
} | ||
|
||
gasLimitForProcessing := tx.GetGasLimit() - gasLimitForMovement | ||
feeForMovement := core.SafeMul(gasPriceForMovement, gasLimitForMovement) | ||
feeForProcessing := core.SafeMul(gasPriceForProcessing, gasLimitForProcessing) | ||
fee := big.NewInt(0).Add(feeForMovement, feeForProcessing) | ||
return fee | ||
} | ||
|
||
// GetTransferredValue - | ||
func (mock *MempoolHostMock) GetTransferredValue(tx data.TransactionHandler) *big.Int { | ||
if mock.GetTransferredValueCalled != nil { | ||
return mock.GetTransferredValueCalled(tx) | ||
} | ||
|
||
return tx.GetValue() | ||
} | ||
|
||
// IsInterfaceNil - | ||
func (mock *MempoolHostMock) IsInterfaceNil() bool { | ||
return mock == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package txcachemocks | ||
|
||
import ( | ||
"math/big" | ||
"sync" | ||
|
||
"github.com/multiversx/mx-chain-core-go/data" | ||
"github.com/multiversx/mx-chain-storage-go/types" | ||
) | ||
|
||
// SelectionSessionMock - | ||
type SelectionSessionMock struct { | ||
mutex sync.Mutex | ||
|
||
AccountStateByAddress map[string]*types.AccountState | ||
GetAccountStateCalled func(address []byte) (*types.AccountState, error) | ||
IsIncorrectlyGuardedCalled func(tx data.TransactionHandler) bool | ||
} | ||
|
||
// NewSelectionSessionMock - | ||
func NewSelectionSessionMock() *SelectionSessionMock { | ||
return &SelectionSessionMock{ | ||
AccountStateByAddress: make(map[string]*types.AccountState), | ||
} | ||
} | ||
|
||
// SetNonce - | ||
func (mock *SelectionSessionMock) SetNonce(address []byte, nonce uint64) { | ||
mock.mutex.Lock() | ||
defer mock.mutex.Unlock() | ||
|
||
key := string(address) | ||
|
||
if mock.AccountStateByAddress[key] == nil { | ||
mock.AccountStateByAddress[key] = newDefaultAccountState() | ||
} | ||
|
||
mock.AccountStateByAddress[key].Nonce = nonce | ||
} | ||
|
||
// SetBalance - | ||
func (mock *SelectionSessionMock) SetBalance(address []byte, balance *big.Int) { | ||
mock.mutex.Lock() | ||
defer mock.mutex.Unlock() | ||
|
||
key := string(address) | ||
|
||
if mock.AccountStateByAddress[key] == nil { | ||
mock.AccountStateByAddress[key] = newDefaultAccountState() | ||
} | ||
|
||
mock.AccountStateByAddress[key].Balance = balance | ||
} | ||
|
||
// GetAccountState - | ||
func (mock *SelectionSessionMock) GetAccountState(address []byte) (*types.AccountState, error) { | ||
mock.mutex.Lock() | ||
defer mock.mutex.Unlock() | ||
|
||
if mock.GetAccountStateCalled != nil { | ||
return mock.GetAccountStateCalled(address) | ||
} | ||
|
||
state, ok := mock.AccountStateByAddress[string(address)] | ||
if ok { | ||
return state, nil | ||
} | ||
|
||
return newDefaultAccountState(), nil | ||
} | ||
|
||
// IsIncorrectlyGuarded - | ||
func (mock *SelectionSessionMock) IsIncorrectlyGuarded(tx data.TransactionHandler) bool { | ||
if mock.IsIncorrectlyGuardedCalled != nil { | ||
return mock.IsIncorrectlyGuardedCalled(tx) | ||
} | ||
|
||
return false | ||
} | ||
|
||
// IsInterfaceNil - | ||
func (mock *SelectionSessionMock) IsInterfaceNil() bool { | ||
return mock == nil | ||
} | ||
|
||
func newDefaultAccountState() *types.AccountState { | ||
return &types.AccountState{ | ||
Nonce: 0, | ||
Balance: big.NewInt(1000000000000000000), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.