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

add etcd compact #17

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions consensus/ethash/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,16 +304,16 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
keccak512 := makeHasher(sha3.NewLegacyKeccak512())

// Calculate the data segment this thread should generate
batch := uint32((size + hashBytes*uint64(threads) - 1) / (hashBytes * uint64(threads)))
first := uint32(id) * batch
batch := (size + hashBytes*uint64(threads) - 1) / (hashBytes * uint64(threads))
first := uint64(id) * batch
limit := first + batch
if limit > uint32(size/hashBytes) {
limit = uint32(size / hashBytes)
if limit > size/hashBytes {
limit = size / hashBytes
}
// Calculate the dataset segment
percent := uint32(size / hashBytes / 100)
for index := first; index < limit; index++ {
item := generateDatasetItem(cache, index, keccak512)
item := generateDatasetItem(cache, uint32(index), keccak512)
if swapped {
swap(item)
}
Expand Down
14 changes: 13 additions & 1 deletion metadium/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ var (

ErrNotRunning = errors.New("Not Running")
ErrAlreadyRunning = errors.New("Already Running")

etcdCompactFrequency = int64(100)
)

func (n *metaNode) eq(m *metaNode) bool {
Expand Down Expand Up @@ -1093,12 +1095,22 @@ func LogBlock(height int64, hash common.Hash) {
}

tstart := time.Now()
if err := admin.etcdPut("metadium-work", string(work)); err != nil {
rev, err := admin.etcdPut("metadium-work", string(work))
if err != nil {
log.Error("Metadium - failed to log the latest block",
"height", height, "hash", hash, "took", time.Since(tstart))
} else {
log.Info("Metadium - logged the latest block",
"height", height, "hash", hash, "took", time.Since(tstart))

if (rev%etcdCompactFrequency == 0) && (rev > 100) {
go func() {
if err := admin.etcdCompact(rev); err != nil {
log.Error("Metadium - failed to compact",
"rev", rev, "took", time.Since(tstart))
}
}()
}
}

admin.blocksMined++
Expand Down
20 changes: 18 additions & 2 deletions metadium/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

"github.com/coreos/etcd/clientv3"
"github.com/coreos/etcd/embed"
"github.com/coreos/etcd/etcdserver/api/membership"
"github.com/coreos/etcd/etcdserver/api/v3client"
Expand Down Expand Up @@ -444,18 +445,33 @@ func (ma *metaAdmin) etcdLeader(locked bool) (uint64, *metaNode) {
return 0, nil
}

func (ma *metaAdmin) etcdPut(key, value string) error {
func (ma *metaAdmin) etcdCompact(rev int64) error {
if !ma.etcdIsRunning() {
return ErrNotRunning
}

ctx, cancel := context.WithTimeout(context.Background(),
ma.etcd.Server.Cfg.ReqTimeout())
defer cancel()
_, err := ma.etcdCli.Put(ctx, key, value)
_, err := ma.etcdCli.Compact(ctx, rev, clientv3.WithCompactPhysical())
// WithCompactPhysical makes Compact wait until all compacted entries are
// removed from the etcd server's storage.
return err
}

func (ma *metaAdmin) etcdPut(key, value string) (int64, error) {
if !ma.etcdIsRunning() {
return 0, ErrNotRunning
}

ctx, cancel := context.WithTimeout(context.Background(),
ma.etcd.Server.Cfg.ReqTimeout())
defer cancel()
// _, err := ma.etcdCli.Put(ctx, key, value)
resp, err := ma.etcdCli.Put(ctx, key, value)
return resp.Header.Revision, err
}

func (ma *metaAdmin) etcdGet(key string) (string, error) {
if !ma.etcdIsRunning() {
return "", ErrNotRunning
Expand Down
2 changes: 1 addition & 1 deletion metadium/scripts/deploy-governance.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var GovernanceDeployer = new function() {
from: this.from,
data: data,
gas: this.gas,
gasPrice: this.gasPrice
gasPrice: this.gasPrice,
nonce: this.nonce()
}
var stx = offlineWalletSignTx(this.wallet.id, tx, eth.chainId())
Expand Down
2 changes: 1 addition & 1 deletion metadium/scripts/genesis-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"istanbulBlock": 0,
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const (
VersionMajor = 0 // Major version component of the current release
VersionMinor = 9 // Minor version component of the current release
VersionPatch = 6 // Patch version component of the current release
VersionPatch = 7 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
)

Expand Down