Skip to content

Commit

Permalink
remove announce related code
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcater committed Aug 15, 2023
1 parent a4e458d commit 13865f0
Show file tree
Hide file tree
Showing 28 changed files with 608 additions and 1,989 deletions.
11 changes: 2 additions & 9 deletions internal/pkg/chainsdk/core/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ func (chain *Chain) HandleTrxPsConn(trx *quorumpb.Trx) error {
switch trx.Type {
case
quorumpb.TrxType_POST,
quorumpb.TrxType_ANNOUNCE,
quorumpb.TrxType_UPD_GRP_USER,
quorumpb.TrxType_CHAIN_CONFIG,
quorumpb.TrxType_APP_CONFIG,
Expand Down Expand Up @@ -724,11 +723,8 @@ func (chain *Chain) ApplyTrxsFullNode(trxs []*quorumpb.Trx, nodename string) err
nodectx.GetNodeCtx().GetChainStorage().AddPost(trx, decodedData, nodename)
case quorumpb.TrxType_UPD_GRP_USER:
chain_log.Debugf("<%s> apply UpdGroupUser trx", chain.groupItem.GroupId)
nodectx.GetNodeCtx().GetChainStorage().UpdateGroupUser(trx.TrxId, decodedData, nodename)
//nodectx.GetNodeCtx().GetChainStorage().UpdateGroupUser(trx.TrxId, decodedData, nodename)
chain.updUserList()
case quorumpb.TrxType_ANNOUNCE:
chain_log.Debugf("<%s> apply ANNOUNCE trx", chain.groupItem.GroupId)
nodectx.GetNodeCtx().GetChainStorage().UpdateAnnounce(decodedData, nodename)
case quorumpb.TrxType_APP_CONFIG:
chain_log.Debugf("<%s> apply APP_CONFIG trx", chain.groupItem.GroupId)
nodectx.GetNodeCtx().GetChainStorage().UpdateAppConfig(decodedData, nodename)
Expand Down Expand Up @@ -803,11 +799,8 @@ func (chain *Chain) ApplyTrxsProducerNode(trxs []*quorumpb.Trx, nodename string)
switch trx.Type {
case quorumpb.TrxType_UPD_GRP_USER:
chain_log.Debugf("<%s> apply USER trx", chain.groupItem.GroupId)
nodectx.GetNodeCtx().GetChainStorage().UpdateGroupUser(trx.TrxId, decodedData, nodename)
//nodectx.GetNodeCtx().GetChainStorage().UpdateGroupUser(trx.TrxId, decodedData, nodename)
chain.updUserList()
case quorumpb.TrxType_ANNOUNCE:
chain_log.Debugf("<%s> apply ANNOUNCE trx", chain.groupItem.GroupId)
nodectx.GetNodeCtx().GetChainStorage().UpdateAnnounce(decodedData, nodename)
case quorumpb.TrxType_CHAIN_CONFIG:
chain_log.Debugf("<%s> apply CHAIN_CONFIG trx", chain.groupItem.GroupId)
nodectx.GetNodeCtx().GetChainStorage().UpdateChainConfig(decodedData, nodename)
Expand Down
92 changes: 0 additions & 92 deletions internal/pkg/chainsdk/core/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,6 @@ func (grp *Group) NewGroup(item *quorumpb.GroupItem) (*quorumpb.Block, error) {
return nil, err
}

//owner announce as the first group producer
group_log.Debugf("<%s> owner announce as the first group producer", grp.Item.GroupId)
aContent := &quorumpb.AnnounceContent{
Type: quorumpb.AnnounceType_AS_PRODUCER,
SignPubkey: item.OwnerPubKey,
EncryptPubkey: item.UserEncryptPubkey,
Memo: "owner announce as the first group producer",
}

aItem := &quorumpb.AnnounceItem{
GroupId: item.GroupId,
Action: quorumpb.ActionType_ADD,
Content: aContent,
AnnouncerPubkey: item.OwnerPubKey,
}

//create hash
byts, err := proto.Marshal(aItem)
if err != nil {
return nil, err
}
aItem.Hash = localcrypto.Hash(byts)
signature, err := ks.EthSignByKeyName(item.GroupId, aItem.Hash)
if err != nil {
return nil, err
}

aItem.Signature = signature

//save announce item to db
err = nodectx.GetNodeCtx().GetChainStorage().AddAnnounceItem(aItem, grp.Nodename)
if err != nil {
return nil, err
}

//add group owner as the first group producer
group_log.Debugf("<%s> add owner as the first producer", grp.Item.GroupId)
pItem := &quorumpb.ProducerItem{}
Expand Down Expand Up @@ -165,8 +130,6 @@ func (grp *Group) JoinGroup(item *quorumpb.GroupItem) error {
grp.ChainCtx = &Chain{}
grp.ChainCtx.NewChain(item, grp.Nodename, false)

ks := nodectx.GetNodeCtx().Keystore

//get consensusInfo from genesis block
//check there is only 1 trx(FORK) in genesis block
if len(item.GenesisBlock.Trxs) != 1 {
Expand Down Expand Up @@ -204,41 +167,6 @@ func (grp *Group) JoinGroup(item *quorumpb.GroupItem) error {
return err
}

//owner announce as the first group producer
group_log.Debugf("<%s> owner announce as the first group producer", grp.Item.GroupId)
aContent := &quorumpb.AnnounceContent{
Type: quorumpb.AnnounceType_AS_PRODUCER,
SignPubkey: item.OwnerPubKey,
EncryptPubkey: item.UserEncryptPubkey,
Memo: "owner announce as the first group producer",
}

aItem := &quorumpb.AnnounceItem{
GroupId: item.GroupId,
Action: quorumpb.ActionType_ADD,
Content: aContent,
AnnouncerPubkey: item.OwnerPubKey,
}

//create hash
byts, err := proto.Marshal(aItem)
if err != nil {
return err
}
aItem.Hash = localcrypto.Hash(byts)
signature, err := ks.EthSignByKeyName(item.GroupId, aItem.Hash)
if err != nil {
return err
}

aItem.Signature = signature

//save announce item to db
err = nodectx.GetNodeCtx().GetChainStorage().AddAnnounceItem(aItem, grp.Nodename)
if err != nil {
return err
}

//add group owner as the first group producer
group_log.Debugf("<%s> add owner as the first producer", grp.Item.GroupId)
pItem := &quorumpb.ProducerItem{}
Expand Down Expand Up @@ -411,16 +339,6 @@ func (grp *Group) GetProducers() ([]*quorumpb.ProducerItem, error) {
return nodectx.GetNodeCtx().GetChainStorage().GetProducers(grp.Item.GroupId, grp.Nodename)
}

func (grp *Group) GetAnnouncedProducer(pubkey string) (*quorumpb.AnnounceItem, error) {
group_log.Debugf("<%s> GetAnnouncedProducer called", grp.Item.GroupId)
return nodectx.GetNodeCtx().GetChainStorage().GetAnnouncedProducer(grp.Item.GroupId, pubkey, grp.Nodename)
}

func (grp *Group) GetAnnouncedUser(pubkey string) (*quorumpb.AnnounceItem, error) {
group_log.Debugf("<%s> GetAnnouncedUser called", grp.Item.GroupId)
return nodectx.GetNodeCtx().GetChainStorage().GetAnnouncedUser(grp.Item.GroupId, pubkey, grp.Nodename)
}

func (grp *Group) GetAppConfigKeyList() (keyName []string, itemType []string, err error) {
group_log.Debugf("<%s> GetAppConfigKeyList called", grp.Item.GroupId)
return nodectx.GetNodeCtx().GetChainStorage().GetAppConfigKey(grp.Item.GroupId, grp.Nodename)
Expand All @@ -435,16 +353,6 @@ func (grp *Group) GetCurrentTrxProposeInterval() (uint64, error) {
return nodectx.GetNodeCtx().GetChainStorage().GetProducerConsensusConfInterval(grp.Item.GroupId, grp.Nodename)
}

// send update announce trx
func (grp *Group) UpdAnnounce(item *quorumpb.AnnounceItem) (string, error) {
group_log.Debugf("<%s> UpdAnnounce called", grp.Item.GroupId)
trx, err := grp.ChainCtx.GetTrxFactory().GetAnnounceTrx("", item)
if err != nil {
return "", nil
}
return grp.sendTrx(trx)
}

// send POST trx
func (grp *Group) PostToGroup(content []byte) (string, error) {
group_log.Debugf("<%s> PostToGroup called", grp.Item.GroupId)
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/chainsdk/def/trxfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

type TrxFactoryIface interface {
GetAnnounceTrx(keyalias string, item *quorumpb.AnnounceItem) (*quorumpb.Trx, error)
GetChainConfigTrx(keyalias string, item *quorumpb.ChainConfigItem) (*quorumpb.Trx, error)
GetUpdAppConfigTrx(keyalias string, item *quorumpb.AppConfigItem) (*quorumpb.Trx, error)
GetUpdGroupUserTrx(keyalias string, item *quorumpb.UpdGroupUserItem) (*quorumpb.Trx, error)
Expand Down
75 changes: 0 additions & 75 deletions internal/pkg/storage/chain/chaindb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,81 +23,6 @@ func NewChainStorage(dbmgr *s.DbMgr) (storage *Storage) {
return storage
}

func (cs *Storage) AddAnnounceItem(item *quorumpb.AnnounceItem, prefix ...string) (err error) {
var key string
if item.Content.Type == quorumpb.AnnounceType_AS_USER {
key = s.GetAnnounceAsUserKey(item.GroupId, item.Content.SignPubkey, prefix...)
} else if item.Content.Type == quorumpb.AnnounceType_AS_PRODUCER {
key = s.GetAnnounceAsProducerKey(item.GroupId, item.Content.SignPubkey, prefix...)
} else {
return fmt.Errorf("unknown announce type %d", item.Content.Type)
}

data, err := proto.Marshal(item)
if err != nil {
chaindb_log.Debugf(err.Error())
return err
}

err = cs.dbmgr.Db.Set([]byte(key), data)
if err != nil {
chaindb_log.Debugf(err.Error())
return err
}

return nil
}

func (cs *Storage) UpdateAnnounce(data []byte, prefix ...string) (err error) {
item := &quorumpb.AnnounceItem{}
if err := proto.Unmarshal(data, item); err != nil {
chaindb_log.Debugf(err.Error())
return err
}

var key string
if item.Content.Type == quorumpb.AnnounceType_AS_USER {
key = s.GetAnnounceAsUserKey(item.GroupId, item.Content.SignPubkey, prefix...)
} else if item.Content.Type == quorumpb.AnnounceType_AS_PRODUCER {
key = s.GetAnnounceAsProducerKey(item.GroupId, item.Content.SignPubkey, prefix...)
} else {
return fmt.Errorf("unknown announce type %d", item.Content.Type)
}

if item.Action == quorumpb.ActionType_ADD {
//check if already exist
exist, err := cs.dbmgr.Db.IsExist([]byte(key))
if exist {
if err != nil {
return err
}
return fmt.Errorf("announce item already exist")
}
//add item to db
err = cs.dbmgr.Db.Set([]byte(key), data)
if err != nil {
chaindb_log.Debugf("error %s", err.Error())
}
} else if item.Action == quorumpb.ActionType_REMOVE {
exist, err := cs.dbmgr.Db.IsExist([]byte(key))
if !exist {
if err != nil {
return err
}
return fmt.Errorf("announce item not exist")
}
//remove item from db
err = cs.dbmgr.Db.Delete([]byte(key))
if err != nil {
chaindb_log.Debugf("error %s", err.Error())
}
} else {
return fmt.Errorf("unknown action type %d", item.Action.Type())
}

return nil
}

func (cs *Storage) AddPost(trx *quorumpb.Trx, decodedData []byte, prefix ...string) error {
key := s.GetPostKey(trx.GroupId, fmt.Sprint(trx.TimeStamp), trx.TrxId, prefix...)

Expand Down
8 changes: 0 additions & 8 deletions internal/pkg/storage/chain/groupdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ func RemoveGroupData(db s.QuorumStorage, groupId string, prefix ...string) error
key = s.GetUserPrefix(groupId, prefix...)
keys = append(keys, key)

//all group announced item
key = s.GetAnnouncedPrefix(groupId, prefix...)
keys = append(keys, key)

//all group schema item
key = s.GetSchemaPrefix(groupId, prefix...)
keys = append(keys, key)

//all group chain_config item
key = s.GetChainConfigPrefix(groupId, prefix...)
keys = append(keys, key)
Expand Down
41 changes: 0 additions & 41 deletions internal/pkg/storage/chain/producerdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,6 @@ func (cs *Storage) RemoveAllProducers(groupId string, prefix ...string) error {
return err
}

func (cs *Storage) GetAnnouncedProducer(groupId string, pubkey string, prefix ...string) (*quorumpb.AnnounceItem, error) {
key := s.GetAnnounceAsProducerKey(groupId, pubkey, prefix...)

value, err := cs.dbmgr.Db.Get([]byte(key))
if err != nil {
return nil, err
}

var ann quorumpb.AnnounceItem
err = proto.Unmarshal(value, &ann)
if err != nil {
return nil, err
}

return &ann, err
}

func (cs *Storage) GetAnnouncedProducers(groupId string, prefix ...string) ([]*quorumpb.AnnounceItem, error) {
var aList []*quorumpb.AnnounceItem
key := s.GetAnnounceAsProducerPrefix(groupId, prefix...)
err := cs.dbmgr.Db.PrefixForeach([]byte(key), func(k []byte, v []byte, err error) error {
if err != nil {
return err
}
item := quorumpb.AnnounceItem{}
perr := proto.Unmarshal(v, &item)
if perr != nil {
return perr
}
aList = append(aList, &item)
return nil
})

return aList, err
}

func (cs *Storage) GetProducers(groupId string, prefix ...string) ([]*quorumpb.ProducerItem, error) {
var pList []*quorumpb.ProducerItem
key := s.GetProducerPrefix(groupId, prefix...)
Expand Down Expand Up @@ -107,11 +71,6 @@ func (cs *Storage) IsProducer(groupId, pubkey string, prefix ...string) (bool, e
return cs.dbmgr.Db.IsExist([]byte(key))
}

func (cs *Storage) IsProducerAnnounced(groupId, pubkey string, prefix ...string) (bool, error) {
key := s.GetAnnounceAsProducerKey(groupId, pubkey, prefix...)
return cs.dbmgr.Db.IsExist([]byte(key))
}

func (cs *Storage) GetProducerConsensusConfInterval(groupId string, prefix ...string) (uint64, error) {
key := s.GetProducerConsensusConfInterval(groupId, prefix...)
value, err := cs.dbmgr.Db.Get([]byte(key))
Expand Down
Loading

0 comments on commit 13865f0

Please sign in to comment.