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

Adding features to mempool to support our pre-ordered txs #2

Merged
merged 21 commits into from
Apr 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
set post-merge at genesis
  • Loading branch information
noot committed Apr 4, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 1a16737426054d7bf0e9cb811ef9377a8370e86d
4 changes: 1 addition & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
@@ -2043,9 +2043,7 @@ func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) (ethapi.Backend
Fatalf("Failed to create the LES server: %v", err)
}
}
// if err := ethcatalyst.Register(stack, backend); err != nil {
// Fatalf("Failed to register the Engine API service: %v", err)
// }

stack.RegisterAPIs(tracers.APIs(backend.APIBackend))
return backend.APIBackend, backend
}
3 changes: 1 addition & 2 deletions common/types.go
Original file line number Diff line number Diff line change
@@ -76,8 +76,7 @@ func (h Hash) Hex() string { return hexutil.Encode(h[:]) }
// TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging.
func (h Hash) TerminalString() string {
//return fmt.Sprintf("%x..%x", h[:3], h[29:])
return h.String()
return fmt.Sprintf("%x..%x", h[:3], h[29:])
}

// String implements the stringer interface and is used also by the logger when
46 changes: 23 additions & 23 deletions consensus/ethash/consensus.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
package ethash

import (
"bytes"
"errors"
"fmt"
"math/big"
@@ -279,11 +280,10 @@ func (ethash *Ethash) verifyHeader(chain consensus.ChainHeaderReader, header, pa
return errOlderBlockTime
}
// Verify the block's difficulty based on its timestamp and parent's difficulty
//expected := ethash.CalcDifficulty(chain, header.Time, parent)

// if expected.Cmp(header.Difficulty) != 0 {
// return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
// }
expected := ethash.CalcDifficulty(chain, header.Time, parent)
if expected.Cmp(header.Difficulty) != 0 {
return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, expected)
}
// Verify that the gas limit is <= 2^63-1
if header.GasLimit > params.MaxGasLimit {
return fmt.Errorf("invalid gasLimit: have %v, max %v", header.GasLimit, params.MaxGasLimit)
@@ -543,15 +543,15 @@ func (ethash *Ethash) verifySeal(chain consensus.ChainHeaderReader, header *type
// Recompute the digest and PoW values
number := header.Number.Uint64()

// var (
// digest []byte
// result []byte
// )
var (
digest []byte
result []byte
)
// If fast-but-heavy PoW verification was requested, use an ethash dataset
if fulldag {
dataset := ethash.dataset(number, true)
if dataset.generated() {
//digest, result = hashimotoFull(dataset.dataset, ethash.SealHash(header).Bytes(), header.Nonce.Uint64())
digest, result = hashimotoFull(dataset.dataset, ethash.SealHash(header).Bytes(), header.Nonce.Uint64())

// Datasets are unmapped in a finalizer. Ensure that the dataset stays alive
// until after the call to hashimotoFull so it's not unmapped while being used.
@@ -565,24 +565,24 @@ func (ethash *Ethash) verifySeal(chain consensus.ChainHeaderReader, header *type
if !fulldag {
cache := ethash.cache(number)

// size := datasetSize(number)
// if ethash.config.PowMode == ModeTest {
// size = 32 * 1024
// }
//digest, result = hashimotoLight(size, cache.cache, ethash.SealHash(header).Bytes(), header.Nonce.Uint64())
size := datasetSize(number)
if ethash.config.PowMode == ModeTest {
size = 32 * 1024
}
digest, result = hashimotoLight(size, cache.cache, ethash.SealHash(header).Bytes(), header.Nonce.Uint64())

// Caches are unmapped in a finalizer. Ensure that the cache stays alive
// until after the call to hashimotoLight so it's not unmapped while being used.
runtime.KeepAlive(cache)
}
// Verify the calculated values against the ones provided in the header
// if !bytes.Equal(header.MixDigest[:], digest) {
// return errInvalidMixDigest
// }
// target := new(big.Int).Div(two256, header.Difficulty)
// if new(big.Int).SetBytes(result).Cmp(target) > 0 {
// return errInvalidPoW
// }
if !bytes.Equal(header.MixDigest[:], digest) {
return errInvalidMixDigest
}
target := new(big.Int).Div(two256, header.Difficulty)
if new(big.Int).SetBytes(result).Cmp(target) > 0 {
return errInvalidPoW
}
return nil
}

@@ -593,7 +593,7 @@ func (ethash *Ethash) Prepare(chain consensus.ChainHeaderReader, header *types.H
if parent == nil {
return consensus.ErrUnknownAncestor
}
header.Difficulty = common.Big0 //ethash.CalcDifficulty(chain, header.Time, parent)
header.Difficulty = ethash.CalcDifficulty(chain, header.Time, parent)
return nil
}

42 changes: 21 additions & 21 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
@@ -262,27 +262,27 @@ func (api *ConsensusAPI) forkchoiceUpdated(update engine.ForkchoiceStateV1, payl
}
return engine.STATUS_SYNCING, nil
}
// // Block is known locally, just sanity check that the beacon client does not
// // attempt to push us back to before the merge.
// if block.Difficulty().BitLen() > 0 || block.NumberU64() == 0 {
// var (
// td = api.eth.BlockChain().GetTd(update.HeadBlockHash, block.NumberU64())
// ptd = api.eth.BlockChain().GetTd(block.ParentHash(), block.NumberU64()-1)
// ttd = api.eth.BlockChain().Config().TerminalTotalDifficulty
// )
// if td == nil || (block.NumberU64() > 0 && ptd == nil) {
// log.Error("TDs unavailable for TTD check", "number", block.NumberU64(), "hash", update.HeadBlockHash, "td", td, "parent", block.ParentHash(), "ptd", ptd)
// return engine.STATUS_INVALID, errors.New("TDs unavailable for TDD check")
// }
// if td.Cmp(ttd) < 0 {
// log.Error("Refusing beacon update to pre-merge", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
// return engine.ForkChoiceResponse{PayloadStatus: engine.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
// }
// if block.NumberU64() > 0 && ptd.Cmp(ttd) >= 0 {
// log.Error("Parent block is already post-ttd", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
// return engine.ForkChoiceResponse{PayloadStatus: engine.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
// }
// }
// Block is known locally, just sanity check that the beacon client does not
// attempt to push us back to before the merge.
if block.Difficulty().BitLen() > 0 || block.NumberU64() == 0 {
var (
td = api.eth.BlockChain().GetTd(update.HeadBlockHash, block.NumberU64())
ptd = api.eth.BlockChain().GetTd(block.ParentHash(), block.NumberU64()-1)
ttd = api.eth.BlockChain().Config().TerminalTotalDifficulty
)
if td == nil || (block.NumberU64() > 0 && ptd == nil) {
log.Error("TDs unavailable for TTD check", "number", block.NumberU64(), "hash", update.HeadBlockHash, "td", td, "parent", block.ParentHash(), "ptd", ptd)
return engine.STATUS_INVALID, errors.New("TDs unavailable for TDD check")
}
if td.Cmp(ttd) < 0 {
log.Error("Refusing beacon update to pre-merge", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
return engine.ForkChoiceResponse{PayloadStatus: engine.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
}
if block.NumberU64() > 0 && ptd.Cmp(ttd) >= 0 {
log.Error("Parent block is already post-ttd", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
return engine.ForkChoiceResponse{PayloadStatus: engine.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
}
}
valid := func(id *engine.PayloadID) engine.ForkChoiceResponse {
return engine.ForkChoiceResponse{
PayloadStatus: engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &update.HeadBlockHash},
1 change: 1 addition & 0 deletions genesis.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
"istanbulBlock": 0,
"berlinBlock": 0,
"londonBlock": 0,
"terminalTotalDifficulty": 0,
"ethash": {}
},
"difficulty": "10000000",
2 changes: 0 additions & 2 deletions grpc/README.md
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ make geth
# generating protobuf files
buf generate buf.build/astria/execution-apis

# TODO - run beacon?

# run geth
./build/bin/geth --goerli --grpc --grpc.addr "0.0.0.0" --grpc.port 50051
```
23 changes: 4 additions & 19 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
@@ -66,7 +66,8 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
if err != nil {
return nil, err
}
// super janky but this is what the payload builder does :/ (miner.worker.buildPayload())

// super janky but this is what the payload builder requires :/ (miner.worker.buildPayload())
// we should probably just execute + store the block directly instead of using the engine api.
time.Sleep(time.Second)
payloadResp, err := s.consensus.GetPayloadV1(*fcStartResp.PayloadID)
@@ -75,14 +76,7 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
return nil, err
}

// _, err = engine.ExecutableDataToBlock(*payloadResp)
// if err != nil {
// log.Error("failed to call ExecutableDataToBlock", "err", err)
// return nil, err
// }

// call blockchain.InsertChain to actually execute and write the blocks to state
// TODO we might not actually need this since the miner loop should seal and call blockchain.WriteBlockAndSetHead
block, err := engine.ExecutableDataToBlock(*payloadResp)
if err != nil {
return nil, err
@@ -98,16 +92,6 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
return nil, fmt.Errorf("failed to insert block into blockchain (n=%d)", n)
}

//payloadStatus := fcStartResp.PayloadStatus
// payloadStatus, err := s.consensus.NewPayloadV1(*payloadResp)
// if err != nil {
// return nil, err
// }
// newForkChoice := &engine.ForkchoiceStateV1{
// HeadBlockHash: payloadResp.BlockHash,
// SafeBlockHash: payloadResp.BlockHash,
// FinalizedBlockHash: payloadResp.BlockHash,
// }
newForkChoice := &engine.ForkchoiceStateV1{
HeadBlockHash: block.Hash(),
SafeBlockHash: block.Hash(),
@@ -120,7 +104,7 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
}

res := &executionv1.DoBlockResponse{
// RENAME THIS - this is not the state root!! it's the block hash
// TODO: RENAME THIS - this is not the state root!! it's the block hash
StateRoot: fcEndResp.PayloadStatus.LatestValidHash.Bytes(),
}
return res, nil
@@ -129,6 +113,7 @@ func (s *ExecutionServiceServer) DoBlock(ctx context.Context, req *executionv1.D
func (s *ExecutionServiceServer) InitState(ctx context.Context, req *executionv1.InitStateRequest) (*executionv1.InitStateResponse, error) {
currHead := s.eth.BlockChain().CurrentHeader()
res := &executionv1.InitStateResponse{
// TODO: RENAME THIS - this is not the state root!! it's the block hash
StateRoot: currHead.Hash().Bytes(),
}

11 changes: 7 additions & 4 deletions private_network.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# private network

### astria
1. Make a new account in Metamask (or whichever method you prefer). Copy paste the address into `genesis.json`'s `alloc` field. This account will be allocated 300 ETH at startup.

2. To build and initialize Geth:
@@ -13,10 +14,12 @@ To run without mining (ie. using the conductor):
./build/bin/geth --datadir ~/.astriageth/ --http --http.port=8545 --ws --ws.port=8545 --networkid=1337 --http.corsdomain='*' --ws.origins='*' --miner.threads 1 --miner.etherbase=0x46B77EFDFB20979E1C29ec98DcE73e3eCbF64102 --grpc --grpc.addr=localhost --grpc.port 50051
```

To run with mining:
Replace the etherbase in the following with your account (it doesn't really matter though, since mining doesn't require signing). Then,
4. Open up Metamask and go to the Localhost 8545 network. You should see your account has 300 ETH. You can now transfer this to other accounts.

### ethash
To run with mining (which you don't want if running Astria):
1. Remove the `"terminalTotalDifficulty": 0,` line in `genesis.json`. Then run steps 1-2 as above.
2. Replace the etherbase in the following with your account (it doesn't really matter though, since mining doesn't require signing). Then,
```bash
./build/bin/geth --datadir ~/.astriageth/ --http --http.port=8545 --ws --ws.port=8545 --networkid=1337 --http.corsdomain='*' --ws.origins='*' --mine --miner.threads 1 --miner.etherbase=0x46B77EFDFB20979E1C29ec98DcE73e3eCbF64102 --grpc --grpc.addr=localhost --grpc.port 50051
```

4. Open up Metamask and go to the Localhost 8545 network. You should see your account has 300 ETH. You can now transfer this to other accounts.