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 events in key places #546

Merged
merged 7 commits into from Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion log/zap.go
Expand Up @@ -42,16 +42,26 @@ func String(name, val string) Field {
return Field(zap.String(name, val))
}

// ByteString returns a byte string ([]byte) Field
func ByteString(name string, val []byte) Field {
return Field(zap.ByteString(name, val))
}

// Int returns an int Field
func Int(name string, val int) Field {
return Field(zap.Int(name, val))
}

// Int32 returns an int Field
// Uint32 returns an uint32 Field
func Uint32(name string, val uint32) Field {
return Field(zap.Uint32(name, val))
}

// Uint64 returns an uint64 Field
func Uint64(name string, val uint64) Field {
return Field(zap.Uint64(name, val))
}

// Namespace make next fields be inside a namespace.
func Namespace(name string) Field {
return Field(zap.Namespace(name))
Expand Down
12 changes: 12 additions & 0 deletions mesh/block.go
Expand Up @@ -36,6 +36,18 @@ type SerializableTransaction struct {
Payload []byte
}

func (t *SerializableTransaction) GetAmount() *big.Int {
Copy link
Contributor

Choose a reason for hiding this comment

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

Amount is better

a := &big.Int{}
a.SetBytes(t.Amount)
return a
}

func (t *SerializableTransaction) GetPrice() *big.Int {
a := &big.Int{}
a.SetBytes(t.Price)
return a
}

func NewBlock(coin bool, data []byte, ts time.Time, layerId LayerID) *Block {
b := Block{
Id: BlockID(uuid.New().ID()),
Expand Down
1 change: 1 addition & 0 deletions mesh/mesh.go
Expand Up @@ -119,6 +119,7 @@ func (m *Mesh) AddLayer(layer *Layer) error {
}
atomic.StoreUint32(&m.lastSeenLayer, uint32(layer.Index()))
m.addLayer(layer)
m.Log.With().Info("added layer", log.Uint32("id", uint32(layer.Index())), log.Int("num of blocks", len(layer.blocks)))
m.SetLatestLayer(uint32(layer.Index()))
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion miner/block_builder.go
Expand Up @@ -154,8 +154,9 @@ func (t *BlockBuilder) listenForTx() {
case <-t.stopChan:
return
case data := <-t.txGossipChannel:
t.Log.Info("got new tx")
x, err := mesh.BytesAsTransaction(bytes.NewReader(data.Bytes()))
t.Log.With().Info("got new tx", log.String("sender", x.Origin.String()), log.String("receiver", x.Recipient.String()),
log.String("amount", x.GetAmount().String()), log.Uint64("nonce", x.AccountNonce), log.Bool("valid", err != nil))
if err != nil {
t.Log.Error("cannot parse incoming TX")
data.ReportValidation(IncomingTxProtocol, false)
Expand Down
9 changes: 7 additions & 2 deletions state/processor.go
Expand Up @@ -112,12 +112,15 @@ func (tp *TransactionProcessor) ApplyTransactions(layer LayerID, transactions Tr
defer tp.mu.Unlock()
failed := tp.Process(tp.randomSort(txs), tp.coalesceTransactionsBySender(txs))
newHash, err := tp.globalState.Commit(false)
tp.Log.Info("new state root for layer %v is %x", layer, newHash)

if err != nil {
tp.Log.Error("db write error %v", err)
return failed, err
}

tp.Log.Info("new state root for layer %v is %x", layer, newHash)
tp.Log.With().Info("new state", log.Uint32("layer id", uint32(layer)), log.String("root hash", newHash.String()))
Copy link
Contributor

Choose a reason for hiding this comment

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

layer id and root hash will be used as json keys. it is less recommended that they have space. replace with _


tp.stateQueue.PushBack(newHash)
if tp.stateQueue.Len() > maxPastStates {
hash := tp.stateQueue.Remove(tp.stateQueue.Back())
Expand All @@ -134,10 +137,12 @@ func (tp *TransactionProcessor) Reset(layer LayerID) {
defer tp.mu.Unlock()
if state, ok := tp.prevStates[layer]; ok {
newState, err := New(state, tp.globalState.db)
tp.Log.Info("reverted, new root %x", newState.IntermediateRoot(false))

if err != nil {
panic("cannot revert- improper state")
}
tp.Log.Info("reverted, new root %x", newState.IntermediateRoot(false))
tp.Log.With().Info("reverted", log.String("root hash", newState.IntermediateRoot(false).String()))
Copy link
Contributor

Choose a reason for hiding this comment

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

replace space here also


tp.globalState = newState
tp.pruneAfterRevert(layer)
Expand Down
2 changes: 1 addition & 1 deletion sync/block_listener.go
Expand Up @@ -86,7 +86,7 @@ func (bl *BlockListener) ListenToGossipBlocks() {
data.ReportValidation(NewBlockProtocol, false)
break
}

bl.Log.With().Info("got new block", log.Uint32("id", uint32(blk.Id)), log.Int("txs", len(blk.Txs)), log.Bool("valid", err == nil))
if bl.BlockEligible(blk.LayerIndex, blk.MinerID) {
data.ReportValidation(NewBlockProtocol, true)
err := bl.AddBlock(&blk)
Expand Down