func (db *InMemoryDB) SetGenesisTime(t uint64, transaction ...interface{}) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	db.genesisTime = t
	return nil
}
SetGenesisTime sets the genesis time for the chain represented by this database.
package db
import (
	"errors"
	"fmt"
	"sync"
	"github.com/libp2p/go-libp2p-core/crypto"
	"github.com/prysmaticlabs/go-ssz"
	"github.com/phoreproject/synapse/chainhash"
	"github.com/phoreproject/synapse/primitives"
)
type InMemoryDB struct {
	DB             map[chainhash.Hash]primitives.Block
	AttestationDB  map[uint32]primitives.Attestation
	head           chainhash.Hash
	justified      chainhash.Hash
	blockNodes     map[chainhash.Hash]BlockNodeDisk
	statemap       map[chainhash.Hash]primitives.State
	genesisTime    uint64
	hostkey        []byte
	finalized      chainhash.Hash
	finalizedState primitives.State
	justifiedState primitives.State
	lock           *sync.Mutex
}
func NewInMemoryDB() *InMemoryDB {
	return &InMemoryDB{
		DB:            make(map[chainhash.Hash]primitives.Block),
		AttestationDB: make(map[uint32]primitives.Attestation),
		blockNodes:    make(map[chainhash.Hash]BlockNodeDisk),
		statemap:      make(map[chainhash.Hash]primitives.State),
		lock:          new(sync.Mutex),
	}
}
func (db *InMemoryDB) GetBlockForHash(h chainhash.Hash, transaction ...interface{}) (*primitives.Block, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	out, found := db.DB[h]
	if !found {
		return nil, fmt.Errorf("could not find block with hash")
	}
	return &out, nil
}
func (db *InMemoryDB) SetBlock(b primitives.Block, transaction ...interface{}) error {
	db.lock.Lock()
	blockHash, _ := ssz.HashTreeRoot(b)
	db.DB[blockHash] = b
	db.lock.Unlock()
	return nil
}
func (db *InMemoryDB) GetLatestAttestation(validator uint32, transaction ...interface{}) (*primitives.Attestation, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	if att, found := db.AttestationDB[validator]; found {
		return &att, nil
	}
	return nil, errors.New("could not find attestation for validator")
}
func (db *InMemoryDB) SetLatestAttestationsIfNeeded(validators []uint32, att primitives.Attestation, transaction ...interface{}) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	for _, validator := range validators {
		if a, found := db.AttestationDB[validator]; found && a.Data.Slot >= att.Data.Slot {
			return nil
		}
		db.AttestationDB[validator] = att
	}
	return nil
}
func (db *InMemoryDB) Close() error {
	return nil
}
func (db *InMemoryDB) SetHeadBlock(h chainhash.Hash, transaction ...interface{}) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	db.head = h
	return nil
}
func (db *InMemoryDB) GetHeadBlock(transaction ...interface{}) (*chainhash.Hash, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	return &db.head, nil
}
func (db *InMemoryDB) GetBlockNode(h chainhash.Hash, transaction ...interface{}) (*BlockNodeDisk, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	if b, found := db.blockNodes[h]; found {
		return &b, nil
	}
	return nil, fmt.Errorf("missing block node %s", h)
}
func (db *InMemoryDB) GetFinalizedHead(transaction ...interface{}) (*chainhash.Hash, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	return &db.finalized, nil
}
func (db *InMemoryDB) GetJustifiedHead(transaction ...interface{}) (*chainhash.Hash, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	return &db.justified, nil
}
func (db *InMemoryDB) SetBlockNode(node BlockNodeDisk, transaction ...interface{}) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	db.blockNodes[node.Hash] = node
	return nil
}
func (db *InMemoryDB) SetFinalizedHead(h chainhash.Hash, transaction ...interface{}) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	db.finalized = h
	return nil
}
func (db *InMemoryDB) SetJustifiedHead(h chainhash.Hash, transaction ...interface{}) error {
	db.lock.Lock()
	defer db.lock.Unlock()
	db.justified = h
	return nil
}
func (db *InMemoryDB) GetGenesisTime(transaction ...interface{}) (uint64, error) {
	db.lock.Lock()
	defer db.lock.Unlock()
	return db.genesisTime, nil
}