-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): Add sync info metrics (#979)
- Loading branch information
Showing
9 changed files
with
141 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package block | ||
|
||
import ( | ||
"github.com/dymensionxyz/dymint/types" | ||
) | ||
|
||
type Cache struct { | ||
// concurrency managed by Manager.retrieverMu mutex | ||
cache map[uint64]types.CachedBlock | ||
} | ||
|
||
func (m *Cache) AddBlockToCache(h uint64, b *types.Block, c *types.Commit) { | ||
m.cache[h] = types.CachedBlock{Block: b, Commit: c} | ||
types.BlockCacheSizeGauge.Set(float64(m.Size())) | ||
} | ||
|
||
func (m *Cache) DeleteBlockFromCache(h uint64) { | ||
delete(m.cache, h) | ||
types.BlockCacheSizeGauge.Set(float64(m.Size())) | ||
} | ||
|
||
func (m *Cache) GetBlockFromCache(h uint64) (types.CachedBlock, bool) { | ||
ret, found := m.cache[h] | ||
return ret, found | ||
} | ||
|
||
func (m *Cache) HasBlockInCache(h uint64) bool { | ||
_, found := m.GetBlockFromCache(h) | ||
return found | ||
} | ||
|
||
func (m *Cache) Size() int { | ||
return len(m.cache) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/libp2p/go-libp2p/core/crypto" | ||
tmcrypto "github.com/tendermint/tendermint/crypto" | ||
) | ||
|
||
type BlockSource uint64 | ||
|
||
const ( | ||
_ BlockSource = iota | ||
ProducedBlock | ||
GossipedBlock | ||
DABlock | ||
LocalDbBlock | ||
) | ||
|
||
func (s BlockSource) String() string { | ||
return AllSources[s] | ||
} | ||
|
||
var AllSources = []string{"none", "produced", "gossip", "da", "local_db"} | ||
|
||
type BlockMetaData struct { | ||
Source BlockSource | ||
DAHeight uint64 | ||
} | ||
|
||
type CachedBlock struct { | ||
Block *Block | ||
Commit *Commit | ||
} | ||
|
||
func GetAddress(key crypto.PrivKey) ([]byte, error) { | ||
rawKey, err := key.GetPublic().Raw() | ||
if err != nil { | ||
return nil, err | ||
} | ||
return tmcrypto.AddressHash(rawKey), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters