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

Beds 526/Raw DB sdk #947

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open

Conversation

Tangui-Bitfly
Copy link
Contributor

@Tangui-Bitfly Tangui-Bitfly commented Oct 14, 2024

  • add db2.BigTableEthRaw which only purpose is reading from the raw bigtable store
  • db2.BigTableEthRaw is a http.RoundTriper, this allow the caller to use when creating a new ethclient.Client
  • introduce the db2.RawStore to handle all interaction with bigtable satore. There are some duplications here, the aim of this pr is not to refactor everything, it's just to provide an easy to use way of retrieving eth data from bigtable
  • it is used as follow
bt, err := store.NewBigTableWithClient(context.Background(), client, admin, raw)
if err != nil {
	t.Fatal(err)
}

rawStore := NewRawStore(store.Wrap(bt, BlocRawTable, ""))

rpcClient, err := rpc.DialOptions(context.Background(), "http://foo.bar", rpc.WithHTTPClient(&http.Client{
	Transport: NewBigTableEthRaw(rawStore, chainID),
}))
ethClient := ethclient.NewClient(rpcClient)

@Tangui-Bitfly Tangui-Bitfly force-pushed the BEDS-526/fix-internal-tx branch 3 times, most recently from e0b6374 to 1fdf888 Compare October 17, 2024 07:18
@Tangui-Bitfly Tangui-Bitfly force-pushed the BEDS-526/fix-internal-tx branch 7 times, most recently from 86d3841 to cd8bbcb Compare November 6, 2024 14:01
db2/BigTableEthRaw: add chainID
db2/BigTableEthRaw: handle index for get uncle
db2/BigTableEthRaw: fix with empty tx
db2/BigTableEthRaw: add real condition test
db2/BigTableEthRaw: add WithFallback
db2/BigTableEthRaw: fallback for unsupported method
db2: add cache to raw store (#966)
db2: better cache + client + update store bigtable + clean up
db2/raw: add EthParse
@Tangui-Bitfly Tangui-Bitfly force-pushed the BEDS-526/fix-internal-tx branch 2 times, most recently from a3eb57f to d7ad639 Compare November 15, 2024 12:54
@Tangui-Bitfly Tangui-Bitfly changed the title Beds 526/fix internal tx Beds 526/Raw DB sdk Nov 19, 2024

- solc is available [here](https://docs.soliditylang.org/en/latest/installing-solidity.html)

- and `abigen` wan be installed through go directly

Choose a reason for hiding this comment

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

Suggested change
- and `abigen` wan be installed through go directly
- and `abigen` can be installed through go directly


head, _ := b.Backend.Client().HeaderByNumber(context.Background(), nil)
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))
chainid, _ := b.Backend.Client().ChainID(context.Background())

Choose a reason for hiding this comment

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

Suggested change
chainid, _ := b.Backend.Client().ChainID(context.Background())
chainid, err := b.Backend.Client().ChainID(context.Background())

func (b *BlockchainBackend) MakeUnsignedTx(t *testing.T, from common.Address, to *common.Address, value *big.Int, data []byte) *types.Transaction {
t.Helper()

head, _ := b.Backend.Client().HeaderByNumber(context.Background(), nil)

Choose a reason for hiding this comment

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

Suggested change
head, _ := b.Backend.Client().HeaderByNumber(context.Background(), nil)
head, err := b.Backend.Client().HeaderByNumber(context.Background(), nil)

we should check for any errors coz we will be accessing the BaseFee value to calculate the gas price

func (b *BlockchainBackend) DeployContract(t *testing.T, contractData []byte) common.Address {
t.Helper()

head, _ := b.Backend.Client().HeaderByNumber(context.Background(), nil)

Choose a reason for hiding this comment

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

Suggested change
head, _ := b.Backend.Client().HeaderByNumber(context.Background(), nil)
head, err := b.Backend.Client().HeaderByNumber(context.Background(), nil)


head, _ := b.Backend.Client().HeaderByNumber(context.Background(), nil)
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(params.GWei))
chainid, _ := b.Backend.Client().ChainID(context.Background())

Choose a reason for hiding this comment

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

Suggested change
chainid, _ := b.Backend.Client().ChainID(context.Background())
chainid, err := b.Backend.Client().ChainID(context.Background())

bk := ethsimtracer.NewBackend(genesis, func(nodeConf *node.Config, ethConf *ethconfig.Config) {
nodeConf.HTTPModules = append(nodeConf.HTTPModules, "debug", "eth")
nodeConf.HTTPHost = "127.0.0.1"
nodeConf.HTTPPort = 4242

Choose a reason for hiding this comment

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

It might be a good idea to move the port value to the top of the file and store it as a constant - it will make it easier to update when needed

return fmt.Errorf("cannot ApplyBulk err: %w", err)
}
// TODO aggregate errs
for _, e := range errs {

Choose a reason for hiding this comment

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

Suggested change
for _, e := range errs {
var bulkErrs []string
for _, e := range errs {
bulkErrs = append(bulkErrs, e.Error())
}
if len(bulkErrs) > 0 {
return fmt.Errorf("cannot ApplyBulk elem, errors: %v", bulkErrs)
}

if err != nil {
return fmt.Errorf("cannot ApplyBulk err: %w", err)
}
// TODO aggregate errs

Choose a reason for hiding this comment

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

Suggested change
// TODO aggregate errs

// Close shuts down the BigTable by closing the Bigtable client connection
// It returns an error if the operation fails
func (b BigTable) Close() error {
if err := b.client.Close(); err != nil && status.Code(err) != codes.Canceled {

Choose a reason for hiding this comment

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

let's also check if the client is not nil before trying to close it

}, {
key: "bar",
}},
expected: []string{"", "", "", ""},

Choose a reason for hiding this comment

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

is this correct expected output?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants