Skip to content

Commit

Permalink
Fix the missing field of topic in the event
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd committed Oct 31, 2024
1 parent 2c2927b commit ff21910
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 69 deletions.
8 changes: 4 additions & 4 deletions precompiles/avs/IAVSManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ interface IAVSManager {
event OperatorJoined(address indexed avsAddr, string sender);
event OperatorLeft(address indexed avsAddr, string sender);
event TaskCreated(
string sender,
uint64 taskId,
address indexed taskContractAddress,
uint64 indexed taskId,
string sender,
string name,
bytes hash,
uint64 taskResponsePeriod,
Expand All @@ -33,11 +33,11 @@ interface IAVSManager {
);
event PublicKeyRegistered(string sender, string name);
event TaskSubmittedByOperator(
address indexed taskContractAddress,
uint64 indexed taskId,
string sender,
uint64 taskID,
bytes taskResponse,
bytes blsSignature,
address indexed taskContractAddress,
uint8 phase
);

Expand Down
42 changes: 21 additions & 21 deletions precompiles/avs/abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,22 @@
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
"indexed": true,
"internalType": "address",
"name": "taskContractAddress",
"type": "address"
},
{
"indexed": false,
"indexed": true,
"internalType": "uint64",
"name": "taskId",
"type": "uint64"
},
{
"indexed": true,
"internalType": "address",
"name": "taskContractAddress",
"type": "address"
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
},
{
"indexed": false,
Expand Down Expand Up @@ -233,17 +233,23 @@
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
"indexed": true,
"internalType": "address",
"name": "taskContractAddress",
"type": "address"
},
{
"indexed": false,
"indexed": true,
"internalType": "uint64",
"name": "taskID",
"name": "taskId",
"type": "uint64"
},
{
"indexed": false,
"internalType": "string",
"name": "sender",
"type": "string"
},
{
"indexed": false,
"internalType": "bytes",
Expand All @@ -256,12 +262,6 @@
"name": "blsSignature",
"type": "bytes"
},
{
"indexed": true,
"internalType": "address",
"name": "taskContractAddress",
"type": "address"
},
{
"indexed": false,
"internalType": "uint8",
Expand Down
238 changes: 196 additions & 42 deletions precompiles/avs/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package avs

import (
"github.com/ethereum/go-ethereum/accounts/abi"
cmn "github.com/evmos/evmos/v16/precompiles/common"

avstypes "github.com/ExocoreNetwork/exocore/x/avs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -52,55 +53,186 @@ func (p Precompile) emitEvent(ctx sdk.Context, stateDB vm.StateDB, eventName str
// - An error if there is an issue packing the event data or adding the log to the state database.
// - nil if the event is successfully emitted.
func (p Precompile) EmitAVSRegistered(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error {
arguments := p.ABI.Events[EventTypeAVSRegistered].Inputs
return p.emitEvent(ctx, stateDB, EventTypeAVSRegistered, arguments,
avs.AvsAddress,
avs.CallerAddress.String(),
avs.AvsName)
event := p.ABI.Events[EventTypeAVSRegistered]
topics := make([]common.Hash, 2)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(avs.AvsAddress)
if err != nil {
return err
}

// Prepare the event data: sender, avsName
arguments := abi.Arguments{event.Inputs[1], event.Inputs[2]}
packed, err := arguments.Pack(avs.CallerAddress.String(), avs.AvsName)
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}

func (p Precompile) EmitAVSUpdated(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error {
arguments := p.ABI.Events[EventTypeAVSUpdated].Inputs
return p.emitEvent(ctx, stateDB, EventTypeAVSUpdated, arguments,
avs.AvsAddress,
avs.CallerAddress.String(),
avs.AvsName)
event := p.ABI.Events[EventTypeAVSUpdated]
topics := make([]common.Hash, 2)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(avs.AvsAddress)
if err != nil {
return err
}

// Prepare the event data: sender, avsName
arguments := abi.Arguments{event.Inputs[1], event.Inputs[2]}
packed, err := arguments.Pack(avs.CallerAddress.String(), avs.AvsName)
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}

func (p Precompile) EmitAVSDeregistered(ctx sdk.Context, stateDB vm.StateDB, avs *avstypes.AVSRegisterOrDeregisterParams) error {
arguments := p.ABI.Events[EventTypeAVSDeregistered].Inputs
return p.emitEvent(ctx, stateDB, EventTypeAVSDeregistered, arguments,
avs.AvsAddress,
avs.CallerAddress.String(),
avs.AvsName)
event := p.ABI.Events[EventTypeAVSDeregistered]
topics := make([]common.Hash, 2)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(avs.AvsAddress)
if err != nil {
return err
}

// Prepare the event data: sender, avsName
arguments := abi.Arguments{event.Inputs[1], event.Inputs[2]}
packed, err := arguments.Pack(avs.CallerAddress.String(), avs.AvsName)
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}

func (p Precompile) EmitOperatorJoined(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.OperatorOptParams) error {
arguments := p.ABI.Events[EventTypeOperatorJoined].Inputs
return p.emitEvent(ctx, stateDB, EventTypeOperatorJoined, arguments,
params.AvsAddress,
params.OperatorAddress.String())
event := p.ABI.Events[EventTypeOperatorJoined]
topics := make([]common.Hash, 2)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(params.AvsAddress)
if err != nil {
return err
}

// Prepare the event data: operatorAddress
arguments := abi.Arguments{event.Inputs[1]}
packed, err := arguments.Pack(params.OperatorAddress.String())
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}

func (p Precompile) EmitOperatorOuted(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.OperatorOptParams) error {
arguments := p.ABI.Events[EventTypeOperatorLeft].Inputs
return p.emitEvent(ctx, stateDB, EventTypeOperatorLeft, arguments,
params.AvsAddress,
params.OperatorAddress.String())
event := p.ABI.Events[EventTypeOperatorLeft]
topics := make([]common.Hash, 2)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(params.AvsAddress)
if err != nil {
return err
}

// Prepare the event data: operatorAddress
arguments := abi.Arguments{event.Inputs[1]}
packed, err := arguments.Pack(params.OperatorAddress.String())
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}

func (p Precompile) EmitTaskCreated(ctx sdk.Context, stateDB vm.StateDB, task *avstypes.TaskInfoParams) error {
arguments := p.ABI.Events[EventTypeTaskCreated].Inputs
return p.emitEvent(ctx, stateDB, EventTypeTaskCreated, arguments,
task.CallerAddress.String(),
task.TaskID,
task.TaskContractAddress,
task.TaskName,
task.Hash,
task.TaskResponsePeriod,
task.TaskChallengePeriod,
task.ThresholdPercentage,
task.TaskStatisticalPeriod)
event := p.ABI.Events[EventTypeTaskCreated]
topics := make([]common.Hash, 3)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(task.TaskContractAddress)
if err != nil {
return err
}

topics[2], err = cmn.MakeTopic(task.TaskID)
if err != nil {
return err
}
// Prepare the event data:sender,name, hash, taskResponsePeriod,taskChallengePeriod,
// thresholdPercentage,taskStatisticalPeriod
arguments := abi.Arguments{
event.Inputs[2], event.Inputs[3], event.Inputs[4],
event.Inputs[5], event.Inputs[6], event.Inputs[7], event.Inputs[8],
}
packed, err := arguments.Pack(task.CallerAddress.String(), task.TaskName, task.Hash, task.TaskResponsePeriod, task.TaskChallengePeriod,
task.ThresholdPercentage, task.TaskStatisticalPeriod)
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}

func (p Precompile) EmitChallengeInitiated(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.ChallengeParams) error {
Expand All @@ -121,12 +253,34 @@ func (p Precompile) EmitPublicKeyRegistered(ctx sdk.Context, stateDB vm.StateDB,
}

func (p Precompile) EmitTaskSubmittedByOperator(ctx sdk.Context, stateDB vm.StateDB, params *avstypes.TaskResultParams) error {
arguments := p.ABI.Events[EventTypeTaskSubmittedByOperator].Inputs
return p.emitEvent(ctx, stateDB, EventTypeTaskSubmittedByOperator, arguments,
params.CallerAddress.String(),
params.TaskID,
params.TaskResponse,
params.BlsSignature,
params.TaskContractAddress,
params.Phase)
event := p.ABI.Events[EventTypeTaskSubmittedByOperator]
topics := make([]common.Hash, 3)

// The first topic is always the signature of the event.
topics[0] = event.ID

var err error
topics[1], err = cmn.MakeTopic(params.TaskContractAddress)
if err != nil {
return err
}

topics[2], err = cmn.MakeTopic(params.TaskID)
if err != nil {
return err
}
// Prepare the event data:sender,TaskResponse, BlsSignature, Phase
arguments := abi.Arguments{event.Inputs[2], event.Inputs[3], event.Inputs[4], event.Inputs[5]}
packed, err := arguments.Pack(params.CallerAddress.String(), params.TaskResponse, params.BlsSignature, params.Phase)
if err != nil {
return err
}

stateDB.AddLog(&ethtypes.Log{
Address: p.Address(),
Topics: topics,
Data: packed,
BlockNumber: uint64(ctx.BlockHeight()),
})
return nil
}
1 change: 1 addition & 0 deletions x/avs/keeper/avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (k *Keeper) GetAVSInfoByTaskAddress(ctx sdk.Context, taskAddr string) types
if taskAddr == "" || taskAddr == (common.Address{}).String() {
return avs
}
taskAddr = strings.ToLower(taskAddr)
k.IterateAVSInfo(ctx, func(_ int64, avsInfo types.AVSInfo) (stop bool) {
if taskAddr == avsInfo.GetTaskAddr() {
avs = avsInfo
Expand Down
Loading

0 comments on commit ff21910

Please sign in to comment.