Currently, in the blockchain-based distributed microgrid trading system, there are some problems, such as low throughput, high delay, and a high communication overhead. To this end, an improved Practical Byzantine Fault Tolerance (PBFT) algorithm (CE-PBFT) suitable for microgrid power trading is proposed. First, a node credit value calculation model is introduced, and nodes are divided into consensus, supervisory, and propagation nodes according to their credit values, forming a hierarchical network structure to ensure the efficiency and reliability of consensus. Secondly, the consensus process is optimized by adopting a segmented consensus mechanism. This approach calculates the consensus rounds for nodes and selects the methods for node-type switching and consensus based on these calculations, reaching dynamic changes in node states and credit values, effectively reducing the communication overhead of node consensus. Finally, the experiments show that compared with the IMPBFT and PBFT algorithms, the CE-PBFT algorithm has better performance in throughput, delay, and communication overhead, with a 22% higher average throughput and 15% lower average delay than the IMPBFT algorithm and a 118% higher average throughput and 87% lower average delay than the PBFT algorithm.