Skip to content

EthStorage Mining #131

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

Open
wants to merge 28 commits into
base: tm_w3q
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1858463
add miner
ping-ke Feb 21, 2023
4a46884
update
ping-ke Feb 23, 2023
17b4172
Merge branch 'tm_w3q' of https://github.com/QuarkChain/go-ethereum in…
ping-ke Feb 24, 2023
8ec4674
add sstorage miner
ping-ke Mar 22, 2023
8417baa
merge tm_w3q
ping-ke Mar 22, 2023
b542236
remove test case
ping-ke Mar 22, 2023
bbb3a9e
fix bug and add storage miner contract param
ping-ke Mar 23, 2023
4ea96ee
update comments
ping-ke Mar 23, 2023
18d57ca
fix bug and resolve comments
ping-ke Mar 27, 2023
268d56d
fix test
ping-ke Mar 27, 2023
f0485b2
add task to sstorage sync to fill up empty KV and change create/verif…
ping-ke Mar 30, 2023
d1010ed
resolve comment: using keystore instead of using nodekey file
ping-ke Mar 30, 2023
9f3d457
merge
ping-ke Mar 31, 2023
6f9cb48
resolve build
ping-ke Mar 31, 2023
80c2bda
resolve
ping-ke Apr 3, 2023
9f5b46c
Merge branch 'tm_w3q' of https://github.com/QuarkChain/go-ethereum in…
ping-ke Apr 3, 2023
78f4e97
update kv size to 128k
ping-ke Apr 5, 2023
6d3f9a7
resolve comments and fix bugs
ping-ke Apr 10, 2023
bf3b5b0
fix bugs
ping-ke Apr 11, 2023
9201fee
Merge branch 'tm_w3q' of https://github.com/QuarkChain/go-ethereum in…
ping-ke Apr 16, 2023
ed2d30b
bug fix
ping-ke Apr 16, 2023
e746402
fix test
ping-ke Apr 16, 2023
53aaf00
bug fix
ping-ke Apr 17, 2023
5bdbcff
fix bug and resolve comments
ping-ke Apr 24, 2023
43e0209
update contract bytecode
ping-ke Apr 24, 2023
5a6ede9
add check fill empty func to sstorage console
ping-ke May 2, 2023
5262933
bug fix
ping-ke May 2, 2023
29c335b
bug fix
ping-ke May 3, 2023
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
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ var (
utils.MinerNoVerifyFlag,
utils.SstorageShardFlag,
utils.SstorageFileFlag,
utils.SstorageMineFlag,
utils.SstorageTXSignerFlag,
utils.SstorageMinerContractFlag,
utils.NATFlag,
utils.NoDiscoverFlag,
utils.DiscoveryV5Flag,
Expand Down
50 changes: 46 additions & 4 deletions cmd/sstorage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"bytes"
"fmt"
"io"
"os"
Expand All @@ -15,7 +16,7 @@ import (
)

var (
chunkLen *uint64
kvLen *uint64
miner *string
filenames *[]string

Expand Down Expand Up @@ -62,8 +63,14 @@ var ShardWriteCmd = &cobra.Command{
Run: runShardWrite,
}

var CheckEmtpyKVsCmd = &cobra.Command{
Use: "check_empty_kvs",
Short: "check empty Kvs have been filled",
Run: runCheckEmtpyKVs,
}

func init() {
chunkLen = CreateCmd.Flags().Uint64("len", 0, "Chunk idx len to create")
kvLen = CreateCmd.Flags().Uint64("kv_len", 0, "kv idx len to create")

filenames = rootCmd.PersistentFlags().StringArray("filename", []string{}, "Data filename")
miner = rootCmd.PersistentFlags().String("miner", "", "miner address")
Expand Down Expand Up @@ -110,9 +117,9 @@ func runCreate(cmd *cobra.Command, args []string) {
}
minerAddr := common.HexToAddress(*miner)

log.Info("Creating data file", "chunkIdx", *chunkIdx, "chunkLen", *chunkLen, "miner", minerAddr, "encodeType", *encodeType)
log.Info("Creating data file", "kvIdx", *kvIdx, "kvLen", *kvLen, "miner", minerAddr, "encodeType", *encodeType)

_, err := sstorage.Create((*filenames)[0], *chunkIdx, *chunkLen, 0, *kvSize, *encodeType, minerAddr)
_, err := sstorage.Create((*filenames)[0], *kvIdx, *kvLen, 0, *kvSize, *encodeType, minerAddr)
if err != nil {
log.Crit("create failed", "error", err)
}
Expand Down Expand Up @@ -231,6 +238,40 @@ func runShardWrite(cmd *cobra.Command, args []string) {
log.Info("Write value", "kvIdx", *kvIdx, "bytes", len(bs))
}

func runCheckEmtpyKVs(cmd *cobra.Command, args []string) {
setupLogger()

if len(*filenames) != 1 {
log.Crit("must provide a filename")
}

var err error
var df *sstorage.DataFile
df, err = sstorage.OpenDataFile((*filenames)[0])
if err != nil {
log.Crit("open failed", "error", err)
}

commit := common.Hash{}
chunkPerKv := df.KVSize() / sstorage.CHUNK_SIZE
startChunkIdx := (*kvIdx) * chunkPerKv
log.Info("start to verify", "kvidx", *kvIdx, "startChunkIdx", startChunkIdx, "EndChunkIdx", df.EndChunkIdx())
for chunkIdx := startChunkIdx; chunkIdx < df.EndChunkIdx(); chunkIdx++ {
maskedChunkData, err := df.Read(chunkIdx, int(sstorage.CHUNK_SIZE))
if err != nil {
log.Warn("read sstorage file failed", "chunkidx", chunkIdx, "error", err)
}
encodeKey := sstorage.CalcEncodeKey(commit, chunkIdx, df.Miner())
unmaskedChunk := sstorage.DecodeChunk(maskedChunkData, 2, encodeKey)
if bytes.Compare(unmaskedChunk, make([]byte, sstorage.CHUNK_SIZE)) != 0 {
log.Warn("verify empty chunk", "chunkidx", chunkIdx)
}
if chunkIdx%(chunkPerKv*100) == 0 {
log.Info("verify verify state", "chunkidx", chunkIdx)
}
}
}

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "sstorage",
Expand All @@ -243,6 +284,7 @@ func init() {
rootCmd.AddCommand(ChunkWriteCmd)
rootCmd.AddCommand(ShardReadCmd)
rootCmd.AddCommand(ShardWriteCmd)
rootCmd.AddCommand(CheckEmtpyKVsCmd)
}

func main() {
Expand Down
21 changes: 21 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,18 @@ var (
Usage: "Add sharded storage data file",
Value: nil,
}
SstorageMineFlag = cli.BoolFlag{
Name: "sstorage.mine",
Usage: "Enable sstorage mining",
}
SstorageTXSignerFlag = cli.StringFlag{
Name: "sstorage.txsigner",
Usage: "Account used to sign tx submit to sstorage miner contract",
}
SstorageMinerContractFlag = cli.StringFlag{
Name: "sstorage.minercontract",
Usage: "Sstorage miner contract",
}
// Logging and debug settings
EthStatsURLFlag = cli.StringFlag{
Name: "ethstats",
Expand Down Expand Up @@ -1137,6 +1149,15 @@ func setSstorage(ctx *cli.Context, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(SstorageFileFlag.Name) {
cfg.SstorageFiles = ctx.GlobalStringSlice(SstorageFileFlag.Name)
}
if ctx.GlobalIsSet(SstorageMineFlag.Name) {
cfg.SstorageMine = ctx.GlobalBool(SstorageMineFlag.Name)
}
if ctx.GlobalIsSet(SstorageTXSignerFlag.Name) {
cfg.SstorageTXSigner = ctx.GlobalString(SstorageTXSignerFlag.Name)
}
if ctx.GlobalIsSet(SstorageMinerContractFlag.Name) {
cfg.SstorageMinerContract = ctx.GlobalString(SstorageMinerContractFlag.Name)
}

sstorage.InitializeConfig()
for _, s := range cfg.SstorageShards {
Expand Down
8 changes: 4 additions & 4 deletions consensus/tendermint/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (g *Governance) NextValidatorsAndPowersForProposal() ([]common.Address, []u
return nil, nil, 0, common.Hash{}, err
}

validators, powers, err := g.getValidatorsAndPowersFromContract(header.Hash())
validators, powers, err := g.getValidatorsAndPowersFromContract(header.Number())
if err != nil {
return nil, nil, 0, common.Hash{}, err
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (g *Governance) NextValidatorsAndPowersAt(remoteChainNumber uint64, hash co
fmt.Errorf("block hash mismatch", "remoteChainNumber hash", header.Hash(), "hash", hash)
}

validators, powers, err := g.getValidatorsAndPowersFromContract(hash)
validators, powers, err := g.getValidatorsAndPowersFromContract(header.Number())
if err != nil {
return nil, nil, err
}
Expand All @@ -141,7 +141,7 @@ func (g *Governance) NextValidatorsAndPowersAt(remoteChainNumber uint64, hash co
}

// getValidatorsAndPowersFromContract get next validators from contract
func (g *Governance) getValidatorsAndPowersFromContract(blockHash common.Hash) ([]common.Address, []uint64, error) {
Copy link

Choose a reason for hiding this comment

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

I am not sure why we need this change here?

Copy link
Author

Choose a reason for hiding this comment

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

as the Ethereum header change, our etherclient cannot get the correct hash, so when we get validators and powers from the contract from Ethereum, it will fail. so change the getValidatorsAndPowersFromContract using a hash to block number.

Copy link
Author

@ping-ke ping-ke Apr 25, 2023

Choose a reason for hiding this comment

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

can move out this change and create an issue to check this issue.

func (g *Governance) getValidatorsAndPowersFromContract(blockNumber *big.Int) ([]common.Address, []uint64, error) {
data, err := g.validatorSetABI.Pack(contractFunc_GetValidator)
if err != nil {
return nil, nil, err
Expand All @@ -154,7 +154,7 @@ func (g *Governance) getValidatorsAndPowersFromContract(blockHash common.Hash) (
Gas: gas,
Data: msgData,
}
result, err := g.client.CallContractAtHash(g.ctx, msg, blockHash)
result, err := g.client.CallContract(g.ctx, msg, blockNumber)
if err != nil {
return nil, nil, err
}
Expand Down
Loading