Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
runs
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear committed Oct 24, 2023
1 parent bf146d5 commit a1133d5
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 470 deletions.
22 changes: 11 additions & 11 deletions contracts/scripts/DeployAndCallERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ import "../lib/forge-std/src/Script.sol";
import "../src/testing/SolmateERC20.sol";

contract DeployAndCallERC20 is Script {
function run() public {
address dropAddress = address(12);
uint256 quantity = 50000;
function run() public {
address dropAddress = address(12);
uint256 quantity = 50000;

vm.startBroadcast();
SolmateERC20 drop = new SolmateERC20();
vm.startBroadcast();
SolmateERC20 drop = new SolmateERC20();

for (uint256 i = 0; i < 66; i++) {
quantity += 50000;
drop.mint(dropAddress, quantity);
}
for (uint256 i = 0; i < 10066; i++) {
quantity += 50000;
drop.mint(dropAddress, quantity);
}

vm.stopBroadcast();
}
vm.stopBroadcast();
}
}
2 changes: 1 addition & 1 deletion cosmos/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

replace (
// We replace `go-ethereum` with `polaris-geth` in order include our required changes.
github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5
github.com/ethereum/go-ethereum => github.com/berachain/polaris-geth v0.0.0-20231024032731-4fdd2b9deba9

// Required at the moment until a bug in the comsos-sdk is fixed.
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down
3 changes: 1 addition & 2 deletions cosmos/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5 h1:qqyoNcIlOSnIuCmofS6HRSrEXcAupPlqgEFtQij35E0=
github.com/berachain/polaris-geth v0.0.0-20231012174642-6e1d46cd32f5/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw=
github.com/berachain/polaris-geth v0.0.0-20231024032731-4fdd2b9deba9 h1:jKshbCaKCMkjWLO6VRL2qK9BkEAMqPgw8GNUx36oRNc=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 h1:41iFGWnSlI2gVpmOtVTJZNodLdLQLn/KsJqFvXwnd/s=
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
Expand Down
2 changes: 1 addition & 1 deletion cosmos/lib/ante/eject.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (e *EjectOnRecheckTxDecorator) AnteHandle(
if wet, ok := utils.GetAs[*types.WrappedEthereumTransaction](msgs[0]); ok {
hash := wet.Unwrap().Hash()
e.seen[hash]++
if e.seen[hash] > 25 { //nolint:gomnd // temp fix.
if e.seen[hash] > 5 { //nolint:gomnd // temp fix.
delete(e.seen, hash) // prevent leak
return ctx, errors.New("recheck tx")
}
Expand Down
7 changes: 5 additions & 2 deletions cosmos/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/miner"

"pkg.berachain.dev/polaris/eth"
"pkg.berachain.dev/polaris/eth/core"
"pkg.berachain.dev/polaris/eth/core/types"
)

Expand All @@ -48,14 +49,16 @@ type EnvelopeSerializer interface {
// Miner implements the baseapp.TxSelector interface.
type Miner struct {
eth.Miner
chain core.Blockchain
serializer EnvelopeSerializer
currentPayload *miner.Payload
}

// New produces a cosmos miner from a geth miner.
func New(gm eth.Miner) *Miner {
func New(gm eth.Miner, chain core.Blockchain) *Miner {
return &Miner{
Miner: gm,
chain: chain,
}
}

Expand Down Expand Up @@ -108,7 +111,7 @@ func (m *Miner) submitPayloadForBuilding(ctx context.Context) error {
func (m *Miner) constructPayloadArgs(ctx sdk.Context) *miner.BuildPayloadArgs {
return &miner.BuildPayloadArgs{
Timestamp: uint64(ctx.BlockTime().Unix()),
FeeRecipient: m.Etherbase(),
FeeRecipient: common.Address{0x01},
Random: common.Hash{}, /* todo: generated random */
Withdrawals: make(types.Withdrawals, 0),
BeaconRoot: &emptyHash,
Expand Down
6 changes: 3 additions & 3 deletions cosmos/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ func New(
panic(err)
}

p.WrappedTxPool = txpool.New(p.TxPool())
p.WrappedMiner = miner.New(p.Miner(), p.Blockchain())

return p
}

// Build is a function that sets up the Polaris struct.
// It takes a BaseApp and an EVMKeeper as arguments.
// It returns an error if the setup fails.
func (p *Polaris) Build(app CosmosApp, ek EVMKeeper) error {
p.WrappedTxPool = txpool.New(p.TxPool())
app.SetMempool(p.WrappedTxPool)

p.WrappedMiner = miner.New(p.Miner())
app.SetPrepareProposal(p.WrappedMiner.PrepareProposal)

if err := ek.Setup(p.Blockchain()); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cosmos/txpool/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func (h *handler) broadcastTransaction(tx *coretypes.Transaction, retries int) {
if sdkerrors.ErrMempoolIsFull.Codespace() == rsp.Codespace &&
rsp.Code == sdkerrors.ErrMempoolIsFull.ABCICode() {
h.logger.Error("failed to broadcast: comet-bft mempool is full", "tx_hash", tx.Hash())
} else if sdkerrors.ErrTxInMempoolCache.Codespace() == rsp.Codespace &&
rsp.Code == sdkerrors.ErrTxInMempoolCache.ABCICode() {
return
} else {
h.logger.Error("failed to broadcast transaction",
"codespace", rsp.Codespace, "code", rsp.Code, "info", rsp.Info, "tx_hash", tx.Hash())
Expand Down
6 changes: 3 additions & 3 deletions cosmos/x/evm/keeper/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func (k *Keeper) ProcessPayloadEnvelope(
envelope engine.ExecutionPayloadEnvelope
)
// TODO: maybe we just consume the block gas limit and call it a day?
sCtx := sdk.UnwrapSDKContext(ctx)
sCtx := sdk.UnwrapSDKContext(ctx).WithGasMeter(storetypes.NewInfiniteGasMeter()).WithKVGasConfig(storetypes.GasConfig{})
gasMeter := sCtx.GasMeter()
blockGasMeter := sCtx.BlockGasMeter()

// Reset GasMeter to 0.
gasMeter.RefundGas(gasMeter.GasConsumed(), "reset before evm block")
blockGasMeter.RefundGas(blockGasMeter.GasConsumed(), "reset before evm block")
defer gasMeter.ConsumeGas(gasMeter.GasConsumed(), "reset after evm")
defer gasMeter.RefundGas(gasMeter.GasConsumed(), "reset after evm")

if err = envelope.UnmarshalJSON(msg.Data); err != nil {
return nil, fmt.Errorf("failed to unmarshal payload envelope: %w", err)
Expand All @@ -60,7 +60,7 @@ func (k *Keeper) ProcessPayloadEnvelope(
}

// Prepare should be moved to the blockchain? THIS IS VERY HOOD YES NEEDS TO BE MOVED.
k.chain.PreparePlugins(ctx)
k.chain.PreparePlugins(sCtx)
if err = k.chain.InsertBlockWithoutSetHead(block); err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions cosmos/x/evm/plugins/block/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (p *plugin) GetHeaderByNumber(number uint64) (*coretypes.Header, error) {
//
// GetHeaderByHash implements core.BlockPlugin.
func (p *plugin) GetHeaderByHash(hash common.Hash) (*coretypes.Header, error) {
numBz := p.ctx.KVStore(p.storekey).Get(hash.Bytes())
numBz := p.ctx.MultiStore().GetKVStore(p.storekey).Get(hash.Bytes())
if numBz == nil {
return nil, core.ErrHeaderNotFound
}
Expand Down Expand Up @@ -95,7 +95,7 @@ func (p *plugin) StoreHeader(header *coretypes.Header) error {
return p.writeGenesisHeaderBytes(headerHash, headerBz)
}

kvstore := p.ctx.KVStore(p.storekey)
kvstore := p.ctx.MultiStore().GetKVStore(p.storekey)
// set header key
kvstore.Set([]byte{types.HeaderKey}, headerBz)

Expand Down Expand Up @@ -139,20 +139,20 @@ func (p *plugin) readHeaderBytes(number uint64) ([]byte, error) {
}

// Unmarshal the header at IAVL height from its context kv store.
return ctx.KVStore(p.storekey).Get([]byte{types.HeaderKey}), nil
return ctx.MultiStore().GetKVStore(p.storekey).Get([]byte{types.HeaderKey}), nil
}

// writeGenesisHeaderBytes writes the genesis header to the kvstore.
//
// GenesisHeaderKey --> Header bytes
// Header Hash --> 0
func (p *plugin) writeGenesisHeaderBytes(headerHash common.Hash, headerBz []byte) error {
p.ctx.KVStore(p.storekey).Set([]byte{types.GenesisHeaderKey}, headerBz)
p.ctx.KVStore(p.storekey).Set(headerHash.Bytes(), new(big.Int).Bytes())
p.ctx.MultiStore().GetKVStore(p.storekey).Set([]byte{types.GenesisHeaderKey}, headerBz)
p.ctx.MultiStore().GetKVStore(p.storekey).Set(headerHash.Bytes(), new(big.Int).Bytes())
return nil
}

// readGenesisHeaderBytes returns the header bytes at the genesis key.
func (p *plugin) readGenesisHeaderBytes() []byte {
return p.ctx.KVStore(p.storekey).Get([]byte{types.GenesisHeaderKey})
return p.ctx.MultiStore().GetKVStore(p.storekey).Get([]byte{types.GenesisHeaderKey})
}
4 changes: 2 additions & 2 deletions cosmos/x/evm/plugins/block/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func mockQueryContext(height int64, _ bool) (sdk.Context, error) {
if err != nil {
return sdk.Context{}, err
}
ctx.KVStore(testutil.EvmKey).Set([]byte{evmtypes.HeaderKey}, headerBz)
ctx.KVStore(testutil.EvmKey).Set(header.Hash().Bytes(), header.Number.Bytes())
p.ctx.MultiStore().GetKVStore(testutil.EvmKey).Set([]byte{evmtypes.HeaderKey}, headerBz)
p.ctx.MultiStore().GetKVStore(testutil.EvmKey).Set(header.Hash().Bytes(), header.Number.Bytes())
return ctx, nil
}

Expand Down
14 changes: 7 additions & 7 deletions cosmos/x/evm/plugins/historical/historical_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *plugin) StoreBlock(block *coretypes.Block) error {

// store block hash to block number.
numBz := sdk.Uint64ToBigEndian(blockNum)
store := p.ctx.KVStore(p.storeKey)
store := p.ctx.MultiStore().GetKVStore(p.storeKey)

// store block num to block
blockBz, err := rlp.EncodeToBytes(block)
Expand Down Expand Up @@ -83,7 +83,7 @@ func (p *plugin) StoreReceipts(blockHash common.Hash, receipts coretypes.Receipt
)
return err
}
prefix.NewStore(p.ctx.KVStore(p.storeKey),
prefix.NewStore(p.ctx.MultiStore().GetKVStore(p.storeKey),
[]byte{types.BlockHashKeyToReceiptsPrefix}).Set(blockHash.Bytes(), receiptsBz)

return nil
Expand All @@ -94,7 +94,7 @@ func (p *plugin) StoreTransactions(
blockNum uint64, blockHash common.Hash, txs coretypes.Transactions,
) error {
// store all txns in the block.
txStore := prefix.NewStore(p.ctx.KVStore(p.storeKey), []byte{types.TxHashKeyToTxPrefix})
txStore := prefix.NewStore(p.ctx.MultiStore().GetKVStore(p.storeKey), []byte{types.TxHashKeyToTxPrefix})
for txIndex, tx := range txs {
txLookupEntry := &coretypes.TxLookupEntry{
Tx: tx,
Expand All @@ -119,7 +119,7 @@ func (p *plugin) StoreTransactions(

// GetBlockByNumber returns the block at the given height.
func (p *plugin) GetBlockByNumber(number uint64) (*coretypes.Block, error) {
store := p.ctx.KVStore(p.storeKey)
store := p.ctx.MultiStore().GetKVStore(p.storeKey)
numBz := sdk.Uint64ToBigEndian(number)
blockBz := prefix.NewStore(store, []byte{types.BlockNumKeyToBlockPrefix}).Get(numBz)
block := &coretypes.Block{}
Expand All @@ -132,7 +132,7 @@ func (p *plugin) GetBlockByNumber(number uint64) (*coretypes.Block, error) {

// GetBlockByHash returns the block at the given hash.
func (p *plugin) GetBlockByHash(blockHash common.Hash) (*coretypes.Block, error) {
store := p.ctx.KVStore(p.storeKey)
store := p.ctx.MultiStore().GetKVStore(p.storeKey)
numBz := prefix.NewStore(
store, []byte{types.BlockHashKeyToNumPrefix}).Get(blockHash.Bytes())
if numBz == nil {
Expand All @@ -153,7 +153,7 @@ func (p *plugin) GetBlockByHash(blockHash common.Hash) (*coretypes.Block, error)
func (p *plugin) GetTransactionByHash(txHash common.Hash) (*coretypes.TxLookupEntry, error) {
// get tx from off chain.
tleBz := prefix.NewStore(
p.ctx.KVStore(p.storeKey), []byte{types.TxHashKeyToTxPrefix}).Get(txHash.Bytes())
p.ctx.MultiStore().GetKVStore(p.storeKey), []byte{types.TxHashKeyToTxPrefix}).Get(txHash.Bytes())
if tleBz == nil {
return nil, core.ErrTxNotFound
}
Expand All @@ -168,7 +168,7 @@ func (p *plugin) GetTransactionByHash(txHash common.Hash) (*coretypes.TxLookupEn
// GetReceiptsByHash returns the receipts with the given block hash.
func (p *plugin) GetReceiptsByHash(blockHash common.Hash) (coretypes.Receipts, error) {
// get receipts from off chain.
receiptsBz := prefix.NewStore(p.ctx.KVStore(p.storeKey),
receiptsBz := prefix.NewStore(p.ctx.MultiStore().GetKVStore(p.storeKey),
[]byte{types.BlockHashKeyToReceiptsPrefix}).Get(blockHash.Bytes())
if receiptsBz == nil {
return nil, fmt.Errorf("failed to find receipts for block hash %s", blockHash.Hex())
Expand Down
3 changes: 3 additions & 0 deletions cosmos/x/evm/plugins/state/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,22 @@ func (p *plugin) InitGenesis(ctx sdk.Context, ethGen *core.Genesis) error {
)
}
} else {
p.CreateAccount(address)
p.SetNonce(address, account.Nonce)
}

// Initialize the account data on the state plugin.
if account.Balance != nil {
p.SetBalance(address, account.Balance)
}

if account.Code != nil {
p.SetCode(address, account.Code)
} else {
// Initialize the code hash to be empty by default.
p.cms.GetKVStore(p.storeKey).Set(CodeHashKeyFor(address), emptyCodeHashBytes)
}

if account.Storage != nil {
p.SetStorage(address, account.Storage)
}
Expand Down
Loading

0 comments on commit a1133d5

Please sign in to comment.